소스 검색

run Uv.init/close just once in the asys tests

Simon Krajewski 6 년 전
부모
커밋
ba4aae70b3

+ 11 - 0
tests/asys/Main.hx

@@ -3,8 +3,17 @@ import utest.ui.Report;
 
 
 import sys.FileSystem;
 import sys.FileSystem;
 
 
+#if hl
+import hl.Uv;
+#elseif eval
+import eval.Uv;
+#elseif neko
+import neko.Uv;
+#end
+
 class Main {
 class Main {
 	public static function main():Void {
 	public static function main():Void {
+		Uv.init();
 		if (FileSystem.exists("resources-rw")) {
 		if (FileSystem.exists("resources-rw")) {
 			function walk(path:String):Void {
 			function walk(path:String):Void {
 				for (f in FileSystem.readDirectory(path)) {
 				for (f in FileSystem.readDirectory(path)) {
@@ -25,5 +34,7 @@ class Main {
 		runner.onTestStart.add(test -> trace("running", Type.getClassName(Type.getClass(test.fixture.target)), test.fixture.method));
 		runner.onTestStart.add(test -> trace("running", Type.getClassName(Type.getClass(test.fixture.target)), test.fixture.method));
 		Report.create(runner);
 		Report.create(runner);
 		runner.run();
 		runner.run();
+		Uv.run(RunDefault);
+		Uv.close();
 	}
 	}
 }
 }

+ 1 - 7
tests/asys/TestBase.hx

@@ -14,17 +14,11 @@ class TestBase {
 	static var helpers:Map<Process, {?exit:ProcessExit}> = [];
 	static var helpers:Map<Process, {?exit:ProcessExit}> = [];
 
 
 	public static function uvSetup():Void {
 	public static function uvSetup():Void {
-		Uv.init();
+
 	}
 	}
 
 
 	public static function uvTeardown():Void {
 	public static function uvTeardown():Void {
 		helperTeardown();
 		helperTeardown();
-		Uv.run(RunDefault);
-		Uv.close();
-	}
-
-	public static function uvRun(?mode:asys.uv.UVRunMode = asys.uv.UVRunMode.RunDefault):Bool {
-		return Uv.run(mode);
 	}
 	}
 
 
 	/**
 	/**

+ 0 - 2
tests/asys/test/TestAsyncFile.hx

@@ -81,7 +81,6 @@ class TestAsyncFile extends Test {
 		});
 		});
 
 
 		eq(asyncDone, 0);
 		eq(asyncDone, 0);
-		TestBase.uvRun();
 	}
 	}
 
 
 	/**
 	/**
@@ -128,6 +127,5 @@ class TestAsyncFile extends Test {
 		});
 		});
 
 
 		eq(asyncDone, 0);
 		eq(asyncDone, 0);
-		TestBase.uvRun();
 	}
 	}
 }
 }

+ 0 - 5
tests/asys/test/TestAsyncFileSystem.hx

@@ -22,7 +22,6 @@ class TestAsyncFileSystem extends Test {
 		}));
 		}));
 
 
 		eq(asyncDone, 0);
 		eq(asyncDone, 0);
-		TestBase.uvRun();
 	}
 	}
 
 
 	function testStat(async:Async) {
 	function testStat(async:Async) {
@@ -72,7 +71,6 @@ class TestAsyncFileSystem extends Test {
 		});
 		});
 
 
 		eq(asyncDone, 0);
 		eq(asyncDone, 0);
-		TestBase.uvRun();
 	}
 	}
 
 
 	@:timeout(3000)
 	@:timeout(3000)
@@ -97,7 +95,6 @@ class TestAsyncFileSystem extends Test {
 
 
 		NewFS.mkdir('$dir/foo');
 		NewFS.mkdir('$dir/foo');
 
 
-		TestBase.uvRun(RunOnce);
 		t(events.length == 1 && events[0].match(Rename("foo")));
 		t(events.length == 1 && events[0].match(Rename("foo")));
 		events.resize(0);
 		events.resize(0);
 
 
@@ -108,12 +105,10 @@ class TestAsyncFileSystem extends Test {
 
 
 		NewFS.rmdir('$dir/foo');
 		NewFS.rmdir('$dir/foo');
 
 
-		TestBase.uvRun(RunOnce);
 		t(events.length == 2 && events[0].match(Rename("foo/hello.txt")));
 		t(events.length == 2 && events[0].match(Rename("foo/hello.txt")));
 		t(events.length == 2 && events[1].match(Rename("foo")));
 		t(events.length == 2 && events[1].match(Rename("foo")));
 		events.resize(0);
 		events.resize(0);
 
 
 		watcher.close();
 		watcher.close();
-		TestBase.uvRun(RunOnce);
 	}
 	}
 }
 }

+ 0 - 6
tests/asys/test/TestDns.hx

@@ -10,8 +10,6 @@ class TestDns extends Test {
 			t(res[0].match(Ipv4(0x7F000001)));
 			t(res[0].match(Ipv4(0x7F000001)));
 			done();
 			done();
 		}));
 		}));
-
-		TestBase.uvRun();
 	}
 	}
 
 
 	function testIpv4(async:Async) {
 	function testIpv4(async:Async) {
@@ -30,8 +28,6 @@ class TestDns extends Test {
 			t(res[0].match(Ipv4(0xFFFFFFFF)));
 			t(res[0].match(Ipv4(0xFFFFFFFF)));
 			done();
 			done();
 		}));
 		}));
-
-		TestBase.uvRun();
 	}
 	}
 
 
 	function testIpv6(async:Async) {
 	function testIpv6(async:Async) {
@@ -50,7 +46,5 @@ class TestDns extends Test {
 			t(res[0].match(Ipv6(beq(_, Bytes.ofHex("4861786520697320617765736F6D6521")) => _)));
 			t(res[0].match(Ipv6(beq(_, Bytes.ofHex("4861786520697320617765736F6D6521")) => _)));
 			done();
 			done();
 		}));
 		}));
-
-		TestBase.uvRun();
 	}
 	}
 }
 }

+ 0 - 4
tests/asys/test/TestIpc.hx

@@ -49,8 +49,6 @@ class TestIpc extends Test {
 					});
 					});
 				});
 				});
 		});
 		});
-
-		TestBase.uvRun();
 	}
 	}
 
 
 	/*
 	/*
@@ -72,8 +70,6 @@ class TestIpc extends Test {
 			});
 			});
 		});
 		});
 		proc.send({message: {a: [1, 2], b: "c", d: true}});
 		proc.send({message: {a: [1, 2], b: "c", d: true}});
-
-		TestBase.uvRun();
 	}
 	}
 	*/
 	*/
 }
 }

+ 1 - 9
tests/asys/test/TestProcess.hx

@@ -5,23 +5,15 @@ import utest.Async;
 
 
 class TestProcess extends Test {
 class TestProcess extends Test {
 	function testPipes(async:Async) {
 	function testPipes(async:Async) {
-		if (Sys.systemName() == "Windows") { // TODO
-			t(true);
-			async.done();
-			return;
-		}
-
 		var proc = asys.Process.spawn("cat");
 		var proc = asys.Process.spawn("cat");
 		proc.stdout.dataSignal.on(data -> {
 		proc.stdout.dataSignal.on(data -> {
 			beq(data, TestConstants.helloBytes);
 			beq(data, TestConstants.helloBytes);
-			proc.kill();
+			// proc.kill(); // TODO: not implemented?
 			proc.close((err) -> {
 			proc.close((err) -> {
 				eq(err, null);
 				eq(err, null);
 				async.done();
 				async.done();
 			});
 			});
 		});
 		});
 		proc.stdin.write(TestConstants.helloBytes);
 		proc.stdin.write(TestConstants.helloBytes);
-
-		TestBase.uvRun();
 	}
 	}
 }
 }

+ 0 - 7
tests/asys/test/TestStreams.hx

@@ -16,8 +16,6 @@ class TestStreams extends Test {
 			aeq(calls, [1, 2, 3]);
 			aeq(calls, [1, 2, 3]);
 			async.done();
 			async.done();
 		});
 		});
-
-		TestBase.uvRun();
 	}
 	}
 
 
 	function testReadHWM(async:Async) {
 	function testReadHWM(async:Async) {
@@ -63,8 +61,6 @@ class TestStreams extends Test {
 				done();
 				done();
 			});
 			});
 		});
 		});
-
-		TestBase.uvRun();
 	}
 	}
 
 
 	function testPassiveRead(async:Async) {
 	function testPassiveRead(async:Async) {
@@ -76,14 +72,11 @@ class TestStreams extends Test {
 		stream.pause();
 		stream.pause();
 
 
 		Sys.sleep(.05);
 		Sys.sleep(.05);
-		TestBase.uvRun(RunOnce);
 
 
 		stream.dataSignal.on((chunk) -> calls.push(chunk.length));
 		stream.dataSignal.on((chunk) -> calls.push(chunk.length));
 		stream.endSignal.once(() -> {
 		stream.endSignal.once(() -> {
 			aeq(calls, [11, 1, 12, 2, 13, 3]);
 			aeq(calls, [11, 1, 12, 2, 13, 3]);
 			async.done();
 			async.done();
 		});
 		});
-
-		TestBase.uvRun();
 	}
 	}
 }
 }

+ 2 - 6
tests/asys/test/TestTcp.hx

@@ -24,6 +24,7 @@ class TestTcp extends Test {
 					done();
 					done();
 				});
 				});
 			}));
 			}));
+			server.unref();
 			server.listeningSignal.on(() -> {
 			server.listeningSignal.on(() -> {
 				t(server.localAddress.match(Network(AddressTools.equals(_, "127.0.0.1".toIp()) => true, 3232)));
 				t(server.localAddress.match(Network(AddressTools.equals(_, "127.0.0.1".toIp()) => true, 3232)));
 				done();
 				done();
@@ -31,8 +32,6 @@ class TestTcp extends Test {
 			server.errorSignal.on(err -> assert());
 			server.errorSignal.on(err -> assert());
 		}, 2);
 		}, 2);
 
 
-		TestBase.uvRun(RunOnce);
-
 		sub(async, done -> {
 		sub(async, done -> {
 			var client:asys.net.Socket = null;
 			var client:asys.net.Socket = null;
 			client = asys.Net.createConnection({
 			client = asys.Net.createConnection({
@@ -55,10 +54,9 @@ class TestTcp extends Test {
 					});
 					});
 				});
 				});
 		});
 		});
-
-		TestBase.uvRun();
 	}
 	}
 
 
+	@:timeout(1500)
 	function testSignals(async:Async) {
 	function testSignals(async:Async) {
 		sub(async, done -> {
 		sub(async, done -> {
 			var client = asys.net.Socket.create();
 			var client = asys.net.Socket.create();
@@ -81,8 +79,6 @@ class TestTcp extends Test {
 					}
 					}
 				});
 				});
 		}, 2);
 		}, 2);
-
-		TestBase.uvRun();
 	}
 	}
 	#end
 	#end
 }
 }

+ 2 - 4
tests/asys/test/TestUdp.hx

@@ -10,6 +10,7 @@ class TestUdp extends Test {
 	function testEcho(async:Async) {
 	function testEcho(async:Async) {
 		sub(async, done -> {
 		sub(async, done -> {
 			var server = asys.net.UdpSocket.create(Ipv4);
 			var server = asys.net.UdpSocket.create(Ipv4);
+			server.unref();
 			server.bind("127.0.0.1".toIp(), 3232);
 			server.bind("127.0.0.1".toIp(), 3232);
 			server.messageSignal.on(msg -> {
 			server.messageSignal.on(msg -> {
 				beq(msg.data, TestConstants.helloBytes);
 				beq(msg.data, TestConstants.helloBytes);
@@ -30,13 +31,12 @@ class TestUdp extends Test {
 				});
 				});
 			});
 			});
 		});
 		});
-
-		TestBase.uvRun();
 	}
 	}
 
 
 	function testEcho6(async:Async) {
 	function testEcho6(async:Async) {
 		sub(async, done -> {
 		sub(async, done -> {
 			var server = asys.net.UdpSocket.create(Ipv6);
 			var server = asys.net.UdpSocket.create(Ipv6);
+			server.unref();
 			server.bind(AddressTools.localhost(Ipv6), 3232);
 			server.bind(AddressTools.localhost(Ipv6), 3232);
 			server.messageSignal.on(msg -> {
 			server.messageSignal.on(msg -> {
 				beq(msg.data, TestConstants.helloBytes);
 				beq(msg.data, TestConstants.helloBytes);
@@ -57,8 +57,6 @@ class TestUdp extends Test {
 				});
 				});
 			});
 			});
 		});
 		});
-
-		TestBase.uvRun();
 	}
 	}
 	#end
 	#end
 }
 }