From 3a03bedcd49d6289b3ee69b927a164e173908d44 Mon Sep 17 00:00:00 2001 From: Marek Kubica Date: Tue, 24 Jul 2018 14:58:59 +0200 Subject: [PATCH 1/4] Add configuration for Travis CI --- .travis.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..dce4668 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,10 @@ +language: c +sudo: required +install: wget https://raw.githubusercontent.com/ocaml/ocaml-ci-scripts/master/.travis-opam.sh +script: bash -ex .travis-opam.sh +env: + global: + - DEPOPTS="*" + - TESTS=true + matrix: + - OCAML_VERSION=4.06 From 61ce2b0dd764b54b0a4c967a143fc3918bf94367 Mon Sep 17 00:00:00 2001 From: Marek Kubica Date: Tue, 24 Jul 2018 15:01:52 +0200 Subject: [PATCH 2/4] Add build status badge --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 0f29740..a79146c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ Thread_pool =========== +[![Build Status](https://travis-ci.org/issuu/thread-pool-async.svg?branch=master)](https://travis-ci.org/issuu/thread-pool-async) + Creates an async thread pool so your blocking calls are contained in threads. Dependencies From 71cf96590a65a7178a0210d5aa6dd595b87a6fc6 Mon Sep 17 00:00:00 2001 From: Marek Kubica Date: Wed, 25 Jul 2018 11:47:56 +0200 Subject: [PATCH 3/4] Fix signatures --- test/test.ml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/test.ml b/test/test.ml index e66b796..9eae491 100644 --- a/test/test.ml +++ b/test/test.ml @@ -14,7 +14,7 @@ let test_simple () = let destroy () = Int.decr states in let worker () = Unix.sleepf 0.005; - `Ok (Int.incr jobs) + return @@ `Ok (Int.incr jobs) in let%bind pool = Thread_pool.init ~name:"unittest" ~threads ~create ~destroy in @@ -44,7 +44,7 @@ let test_error () = failwith "Stop" | _ -> Unix.sleepf 0.005; - `Ok (Int.incr jobs) + return @@ `Ok (Int.incr jobs) in let%bind pool = Thread_pool.init ~name:"unittest" ~threads ~create ~destroy:ignore in @@ -70,7 +70,7 @@ let test_retry () = | false -> `Ok (Int.incr work_done) in should_fail := false; - result + return result in let%bind pool = Thread_pool.init ~name:"unittest" ~threads ~create ~destroy in let%bind _result = List.init work_expected ~f:ignore |> Deferred.Or_error.List.iter ~how:`Parallel ~f:(fun () -> Thread_pool.with' ~retries:1 pool (worker (ref true))) in @@ -89,7 +89,7 @@ let test_retry_fail () = let destroy = ignore in let worker () = Int.incr tries; - `Attempt_retry + return `Attempt_retry in let%bind pool = Thread_pool.init ~name:"unittest" ~threads ~create ~destroy in let%bind result = List.init work ~f:ignore |> Deferred.Or_error.List.iter ~how:`Parallel ~f:(fun () -> Thread_pool.with' ~retries:0 pool worker) in From bbf53d19e33081d2e354fc369f4669cbddd12634 Mon Sep 17 00:00:00 2001 From: Marek Kubica Date: Wed, 25 Jul 2018 12:01:32 +0200 Subject: [PATCH 4/4] Remove blocking IO in tests --- test/dune | 2 +- test/test.ml | 7 ++++--- thread-pool-async.opam | 1 + 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/test/dune b/test/dune index ac74a09..1e1b155 100644 --- a/test/dune +++ b/test/dune @@ -1,7 +1,7 @@ (executable (name test) (preprocess (pps ppx_let)) - (libraries alcotest alcotest-async thread_pool)) + (libraries alcotest alcotest-async thread_pool core async_kernel async_unix)) (alias (name runtest) diff --git a/test/test.ml b/test/test.ml index 9eae491..e7038aa 100644 --- a/test/test.ml +++ b/test/test.ml @@ -1,5 +1,6 @@ -open Base +open Core open Async_kernel +open Async_unix let unit_or_error = (* exact error does not matter *) @@ -13,7 +14,7 @@ let test_simple () = let create () = Int.incr states in let destroy () = Int.decr states in let worker () = - Unix.sleepf 0.005; + let%bind () = after (Time.Span.of_ms 5.) in return @@ `Ok (Int.incr jobs) in @@ -43,7 +44,7 @@ let test_error () = Int.incr errors; failwith "Stop" | _ -> - Unix.sleepf 0.005; + let%bind () = after (Time.Span.of_ms 5.) in return @@ `Ok (Int.incr jobs) in diff --git a/thread-pool-async.opam b/thread-pool-async.opam index 326b99d..c9f14ab 100644 --- a/thread-pool-async.opam +++ b/thread-pool-async.opam @@ -14,4 +14,5 @@ depends: [ "ppx_let" {>= "v0.9" & < "v0.12"} "alcotest" {test} "alcotest-async" {test} + "core" {test & >= "v0.9" & < "v0.12"} ]