Skip to content

Commit 9b2cdbd

Browse files
committed
Port Poll tests to Windows
Part of #51.
1 parent a2f83d2 commit 9b2cdbd

File tree

2 files changed

+31
-18
lines changed

2 files changed

+31
-18
lines changed

test/poll.ml

+30-17
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,41 @@
55

66
open Test_helpers
77

8-
let test_fd =
9-
if Sys.win32 then
10-
Luv.Process.stderr
11-
else begin
12-
(* On Linux in Travis, trying to create a poll handle for STDERR results in
13-
EPERM, so we create a dummy pipe instead. We don't bother closing it:
14-
only one will be created on tester startup, and it will be closed by the
15-
system on process exit. *)
16-
let (_read_end, write_end) = Unix.pipe () in
17-
(Obj.magic write_end : int)
8+
let with_test_fd f =
9+
let address = fresh_address () in
10+
11+
let server = Luv.TCP.init () |> check_success_result "server init" in
12+
let remote_client =
13+
Luv.TCP.init () |> check_success_result "remote client init" in
14+
Luv.TCP.bind server address |> check_success_result "bind";
15+
Luv.Stream.listen server begin fun result ->
16+
check_success_result "listen" result;
17+
Luv.Stream.accept ~server ~client:remote_client
18+
|> check_success_result "accept"
19+
end;
20+
21+
let client = Luv.TCP.init () |> check_success_result "client init" in
22+
Luv.TCP.connect client address begin fun result ->
23+
check_success_result "connect" result;
24+
let os_socket = Luv.Handle.fileno client |> check_success_result "fileno" in
25+
let os_socket : Luv.Os_fd.Socket.t = Obj.magic os_socket in
26+
f (os_socket);
27+
Luv.Handle.close client ignore;
28+
Luv.Handle.close remote_client ignore
1829
end
1930

2031
let with_poll f =
21-
let poll =
22-
Luv.Poll.init test_fd
23-
|> check_success_result "init"
24-
in
32+
with_test_fd begin fun socket ->
33+
let poll =
34+
Luv.Poll.init_socket socket
35+
|> check_success_result "init_socket"
36+
in
2537

26-
f poll;
38+
f poll;
2739

28-
Luv.Handle.close poll ignore;
29-
run ()
40+
Luv.Handle.close poll ignore;
41+
run ()
42+
end
3043

3144
let tests = [
3245
"poll", [

test/tester.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ let () =
1111
Timer.tests;
1212
Loop_watcher.tests;
1313
Async.tests;
14-
if not Sys.win32 then Poll.tests else [];
14+
Poll.tests;
1515
if not Sys.win32 then Signal.tests else [];
1616
TCP.tests;
1717
if not Sys.win32 then Pipe.tests else [];

0 commit comments

Comments
 (0)