Skip to content

Commit

Permalink
Convert Async tests to cram tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aantron committed Jan 16, 2024
1 parent d9c9487 commit 5ed67db
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 1 deletion.
12 changes: 12 additions & 0 deletions test/unit/async/async.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
$ dune exec ./trivial.exe
Ok

$ dune exec ./send.exe
Async

$ dune exec ./multithreading.exe
Async

$ dune exec ./exception.exe
Exception
Ok
17 changes: 17 additions & 0 deletions test/unit/async/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
(cram
(deps
trivial.exe
send.exe
multithreading.exe
exception.exe
))

(executables
(names
trivial
send
multithreading
exception
)
(libraries luv unit_helpers)
(flags -open Unit_helpers))
17 changes: 17 additions & 0 deletions test/unit/async/exception.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
let () =
Luv.Async.init (fun _async -> raise Exit)
|> ok "async init" @@ fun async ->

Luv.Error.set_on_unhandled_exception begin function
| Exit ->
print_endline "Exception";
Luv.Handle.close async ignore
| _ ->
()
end;

Luv.Async.send async |> ok "send" @@ fun () ->

Luv.Loop.run () |> ignore;

print_endline "Ok"
13 changes: 13 additions & 0 deletions test/unit/async/multithreading.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
let () =
Luv.Async.init begin fun async ->
print_endline "Async";
Luv.Handle.close async ignore
end
|> ok "async init" @@ fun async ->

ignore @@ Thread.create begin fun () ->
Unix.sleepf 0.2;
Luv.Async.send async |> ignore
end ();

Luv.Loop.run () |> ignore
10 changes: 10 additions & 0 deletions test/unit/async/send.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
let () =
Luv.Async.init begin fun async ->
print_endline "Async";
Luv.Handle.close async ignore
end
|> ok "async init" @@ fun async ->

Luv.Async.send async |> ok "send" @@ fun () ->

Luv.Loop.run () |> ignore
4 changes: 4 additions & 0 deletions test/unit/async/trivial.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
let () =
Luv.Async.init ignore |> ok "init" @@ fun async ->
Luv.Handle.close async ignore;
print_endline "Ok"
2 changes: 1 addition & 1 deletion test/unit/timer/multithreading.ml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ let () =
Luv.Loop.run () |> ignore;
let elapsed = Unix.gettimeofday () -. start_time in

Printf.printf "%b\n" (elapsed < 2.5)
Printf.printf "%b\n" (elapsed < 0.5)

0 comments on commit 5ed67db

Please sign in to comment.