Skip to content

Instantly share code, notes, and snippets.

@andreas
Last active August 29, 2015 13:57
Show Gist options
  • Select an option

  • Save andreas/9802796 to your computer and use it in GitHub Desktop.

Select an option

Save andreas/9802796 to your computer and use it in GitHub Desktop.
open Core.Std
open Async.Std
module Ints = struct
type t = int
let to_string = string_of_int
let of_string = int_of_string
end
module IntCache = Memcached.Make(Ints)
let int_suite = TestAsync.(
create ~before_all:(fun () ->
IntCache.connect "localhost" 11212
)
~before:(fun cache ->
return cache
)
~after:(fun cache ->
IntCache.flush cache
>>= fun _ -> Deferred.unit
)
~after_all:(fun cache ->
IntCache.close cache
)
|> test "set" (fun cache ->
Bool.assert_equal (IntCache.set cache "foo" 1) true
)
|> test "get" (fun cache ->
IntCache.set cache "foo" 1 >>= fun _ ->
Int.assert_equal (IntCache.get cache "foo") 1
)
|> test "get missing" (fun cache ->
assert_error (IntCache.get cache "foo") "Not found"
)
|> test "flush" (fun cache ->
IntCache.set cache "foo" 1 >>= fun _ ->
IntCache.flush cache >>= fun _ ->
assert_error (IntCache.get cache "foo") "Not found"
)
|> test "delete" (fun cache ->
IntCache.set cache "foo" 1 >>= fun _ ->
IntCache.delete cache "foo" >>= fun _ ->
assert_error (IntCache.get cache "foo") "Not found"
)
)
let main () =
TestAsync.run int_suite >>> fun _ ->
Async_unix.Shutdown.shutdown 1
in
main ();
Scheduler.go ()
@KennethAdamMiller
Copy link
Copy Markdown

Where's the TestAsync module supposed to be coming from?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment