Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

file 50 lines (46 sloc) 1.676 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
(*
* Copyright (C) 2006-2009 Citrix Systems Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; version 2.1 only. with the special
* exception on linking described in file LICENSE.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*)
open Pervasiveext
open Watch
open Xenstore

module Tests = struct
  let title name =
    Printf.printf "Waiting for %s: " name;
    flush stdout

  let all ~xs =
    title "key /test/one to appear";
    Printf.printf "read %s\n" (wait_for ~xs (value_to_appear "/test/one"));
    title "key /test/one to disappear";
    wait_for ~xs (key_to_disappear "/test/one");
    Printf.printf "OK\n";

    title "both /test/one and /test/two to appear";
    begin
      match wait_for ~xs (all_of [ value_to_appear "/test/one"; value_to_appear "/test/two" ]) with
      | [ a; b ] ->
Printf.printf "values %s and %s\n" a b
      | _ -> failwith "arity mismatch"
    end;
    title "either of /test/one or /test/two to disappear";
    begin
      match fst (wait_for ~xs (any_of [ `One, key_to_disappear "/test/one"; `Two, key_to_disappear "/test/two" ])) with
      | `One -> Printf.printf "/test/one\n"
      | `Two -> Printf.printf "/test/two\n"
    end
  let go () =
    let xs = Xs.daemon_open () in
    finally
      (fun () -> all ~xs)
      (fun () -> Xs.close xs)
end

let _ = Tests.go ()
Something went wrong with that request. Please try again.