Skip to content

Commit

Permalink
Adjust tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Frixuu committed Sep 30, 2024
1 parent 6c46d12 commit 6ce4271
Show file tree
Hide file tree
Showing 12 changed files with 22 additions and 68 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ jobs:
run: npx haxe tests.hxml
- name: run test
run: hl test.hl
timeout-minutes: 5
8 changes: 2 additions & 6 deletions tests/Request.hx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Request {
});
app.listen(2000, false);

sys.thread.Thread.create(() -> {
{
var response = Http.requestUrl("http://localhost:2000");
if (response != data)
throw "post response data does not match: " + response + " data: " + data;
Expand All @@ -26,12 +26,8 @@ class Request {
if (http.responseData != data + data)
throw "post response data does not match: " + http.responseData + " data: " + data + data;
app.close();
});

while (app.server.running) {
app.server.update(false);
Sys.sleep(0.2);
}

trace("done");
}
}
8 changes: 2 additions & 6 deletions tests/TestCompression.hx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class TestCompression {
}, Compression.deflateCompressionMiddleware);
app.listen(2000, false);

sys.thread.Thread.create(() -> {
{
var http = new Http("http://localhost:2000");
var response:Bytes = null;
http.onBytes = function(bytes) {
Expand All @@ -29,12 +29,8 @@ class TestCompression {
if (response.compare(compressedData) != 0)
throw "get response compressed data does not match: " + response + " compressedData: " + compressedData;
app.close();
});

while (app.server.running) {
app.server.update(false);
Sys.sleep(0.2);
}

trace("done");
}
}
8 changes: 2 additions & 6 deletions tests/TestCookie.hx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class TestCookie {
});
app.listen(2000, false);

sys.thread.Thread.create(() -> {
{
var http = new Http("http://localhost:2000");
http.onStatus = function(status) {
if (status == 200) {
Expand All @@ -30,12 +30,8 @@ class TestCookie {
http.request(false);

app.close();
});

while (app.server.running) {
app.server.update(false);
Sys.sleep(0.2);
}

trace("done");
}
}
8 changes: 2 additions & 6 deletions tests/TestMiddlewareCorrectOrder.hx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class TestMiddlewareCorrectOrder {
app.get("/", (_, res) -> res.send('$v1$v2$v3'));
app.listen(2000, false);

Thread.create(() -> {
{
final http = new Http("http://localhost:2000");
var response:Null<Bytes> = null;
http.onBytes = bytes -> response = bytes;
Expand All @@ -40,12 +40,8 @@ class TestMiddlewareCorrectOrder {
if (response.toString() != "bazbarfoo")
throw "not the response we expected";
app.close();
});
};

while (app.server.running) {
app.server.update(false);
Sys.sleep(0.2);
}
trace("done");
}
}
8 changes: 2 additions & 6 deletions tests/TestMiddlewareShortCircuit.hx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class TestMiddlewareShortCircuit {
});
app.listen(2000, false);

Thread.create(() -> {
{
final http = new Http("http://localhost:2000");
var response:Null<Bytes> = null;
http.onBytes = bytes -> response = bytes;
Expand All @@ -23,12 +23,8 @@ class TestMiddlewareShortCircuit {
if (response.toString() != "foo")
throw "not the response we expected";
app.close();
});

while (app.server.running) {
app.server.update(false);
Sys.sleep(0.2);
}

trace("done");
}
}
8 changes: 2 additions & 6 deletions tests/TestPath.hx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class TestPath {
});
app.listen(2000, false);

sys.thread.Thread.create(() -> {
{
var response = Http.requestUrl("http://localhost:2000/path");
if (response != data)
throw "/path: post response data does not match: " + response + " data: " + data;
Expand All @@ -48,12 +48,8 @@ class TestPath {
}
}
app.close();
});

while (app.server.running) {
app.server.update(false);
Sys.sleep(0.2);
}

trace("done");
}
}
8 changes: 2 additions & 6 deletions tests/security/TestCredentialsProvider.hx
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,15 @@ class TestCredentialsProvider {
app.users(credentialsProvider);
app.listen(2000, false);

sys.thread.Thread.create(() -> {
{
var response = Http.requestUrl("http://localhost:2000/users");
var testValue = '{"users":[{"username":"johndoe","email":"[email protected]","full_name":"John Doe","disabled":false}]}';
if (response != testValue)
trace("/users: response data does not match: " + response + " data: " + testValue);

app.close();
});

while (app.server.running) {
app.server.update(false);
Sys.sleep(0.2);
}

trace("done");
}
}
7 changes: 1 addition & 6 deletions tests/security/TestEndpointExample.hx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class TestEndpointExample {
var password = "secret";
var scope = "";

sys.thread.Thread.create(() -> {
{
var http = new Http("http://localhost:2000/token");
http.setPostData('grant_type=${grant_type}&username=${username}&password=${password}&scope=${scope}');
http.request(false);
Expand Down Expand Up @@ -73,11 +73,6 @@ class TestEndpointExample {
throw "/users/me/: response data does not match: " + usersMeItemsRequest.responseData + " data: " + testItemsGet;

app.close();
});

while (app.server.running) {
app.server.update(false);
Sys.sleep(0.2);
}

trace("done");
Expand Down
8 changes: 2 additions & 6 deletions tests/security/TestJwks.hx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class TestJwks {
app.jwks(jwks);
app.listen(2000, false);

sys.thread.Thread.create(() -> {
{
var response = Http.requestUrl("http://localhost:2000/jwks");
var testValue = '{"keys":[]}';
if (response != testValue)
Expand All @@ -36,12 +36,8 @@ class TestJwks {
throw "/jwks: response data does not match: " + responseAfterPost + " data: " + testValueGet;

app.close();
});

while (app.server.running) {
app.server.update(false);
Sys.sleep(0.2);
}

trace("done");
}

Expand Down
9 changes: 2 additions & 7 deletions tests/security/TestOAuth2.hx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package tests.security;
import haxe.Http;
import haxe.Json;
import weblink.security.CredentialsProvider;
import weblink.security.OAuth.OAuthEndpoints;
import weblink.security.OAuth;

class TestOAuth2 {
Expand All @@ -23,7 +22,7 @@ class TestOAuth2 {
var password = "secret";
var scope = "";

sys.thread.Thread.create(() -> {
{
var http = new Http("http://localhost:2000/token");
http.setPostData('grant_type=${grant_type}&username=${username}&password=${password}&scope=${scope}');
http.request(false);
Expand All @@ -36,12 +35,8 @@ class TestOAuth2 {
throw 'empty access token';
}
app.close();
});

while (app.server.running) {
app.server.update(false);
Sys.sleep(0.2);
}

trace("done");
}

Expand Down
9 changes: 2 additions & 7 deletions weblink/_internal/Server.hx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package weblink._internal;

import haxe.MainLoop;
import haxe.io.Bytes;
import hl.uv.Loop;
import sys.net.Host;
Expand Down Expand Up @@ -111,12 +110,8 @@ class Server extends SocketServer {
}
}

public function update(blocking:Bool = true) {
do {
@:privateAccess MainLoop.tick(); // for timers
loop.run(NoWait);
} while (running && blocking);
}
@:deprecated("Updates are now done in a background thread. You should remove this call.")
public function update(blocking:Bool = true) {}

private inline function waitUntilClosed() {
this.closeCondition.wait();
Expand Down

0 comments on commit 6ce4271

Please sign in to comment.