Permalink
Browse files

extra testcase to expose Baardskeerder's problem with empty transactions

  • Loading branch information...
1 parent 299420f commit 093c96171d95b179fb8522561ee56b591065c7db Romain Slootmaekers committed Feb 6, 2013
Showing with 34 additions and 14 deletions.
  1. +5 −3 pylabs/test/server/quick/system_tests_basic.py
  2. +2 −10 src/hope/bstore.ml
  3. +21 −0 src/hope/bstore_test.ml
  4. +6 −1 src/hope/dispatcher.ml
@@ -149,7 +149,7 @@ def tes_and_set_scenario( start_suffix, protocol_version): #tes is deliberate
old_value_prefix = "old_"
new_value_prefix = "new_"
- n = 1#000
+ n = 1000
try:
for i in range (n):
@@ -163,11 +163,13 @@ def tes_and_set_scenario( start_suffix, protocol_version): #tes is deliberate
X.logging.debug("so far so good, now getting_value")
set_value = client.get ( key )
assert_equals( set_value, new_value )
-
+ X.logging.debug("first test_and_set succeeded")
+ X.logging.debug("try test_and_set with different expected value")
set_value = client.testAndSet( key, old_value, old_value )
assert_equals( set_value, new_value )
-
+ X.logging.debug("returned value is ok")
set_value = client.get ( key )
+ X.logging.debug("set_value = %s", set_value)
assert_not_equals( set_value, old_value )
try:
View
@@ -101,10 +101,6 @@ module BStore = (struct
end
| Core.TEST_AND_SET (k,eo,wo) ->
begin
- Lwtc.log "test_and_set (%s,%s,%s)" k
- (Log_extra.string_option_to_string eo)
- (Log_extra.string_option_to_string wo)
- >>= fun () ->
_check_interval t k
(fun k ->
let pk = pref_key k in
@@ -115,8 +111,6 @@ module BStore = (struct
and set w =
begin
BS.set tx pk w >>= fun () ->
- Lwtc.log "returning %S" (Log_extra.string_option_to_string eo)
- >>= fun ()->
Lwt.return (OK eo)
end
in
@@ -134,19 +128,17 @@ module BStore = (struct
end
| Some e ->
begin
- Lwtc.log "hiere" >>= fun () ->
BS.get tx pk >>= function
| OK v ->
- Lwtc.log "test_and_set: %s got %s" pk v >>= fun() ->
if v = e
then
- Lwtc.log "test_and_set %s==%s" v e >>= fun ()->
match wo with
| None -> delete()
| Some w -> set w
else
Lwt.return (OK (Some v))
- | NOK _ -> Lwt.return (OK None)
+ | NOK _ ->
+ Lwt.return (OK None)
end
)
View
@@ -40,7 +40,28 @@ let t_log () =
let main_t () = lwt_wrap setup () test teardown in
Lwt_main.run (main_t())
+
+let t_test_and_set () =
+ let test(fn,t) =
+ let fn = Filename.temp_file "t_test_and_set_" ".bs" in
+ BStore.init fn >>= fun () ->
+ BStore.create fn false >>= fun t ->
+ let key = "x" in
+ let u = TEST_AND_SET(key ,None, Some"X") in
+ BStore.log t true u >>= fun _ ->
+ let u2 = TEST_AND_SET (key, Some "Y", Some "Z") in
+ BStore.log t true u2 >>= fun _ ->
+ BStore.commit t (Core.ITick.from_int64 2L) >>= fun _ ->
+ BStore.get t key >>= fun vo ->
+ Lwtc.log "got %s" (Log_extra.string_option_to_string vo) >>= fun () ->
+ OUnit.assert_equal ~printer:Log_extra.string_option_to_string vo (Some "X");
+ Lwt.return ()
+ in
+ let main_t () = lwt_wrap setup () test teardown in
+ Lwt_main.run (main_t())
+
let suite =
"Bstore" >:::[
"log" >:: t_log;
+ "test_and_set" >:: t_test_and_set;
]
View
@@ -80,6 +80,9 @@ module ADispatcher (S:STORE) = struct
let handle_commit t s i u m_w to_client =
let () = validate_commit_update i s.accepted in
commit_update t i >>= fun () ->
+ Lwtc.log "commited i:%s to_client:%s"
+ (ITickUtils.tick2s i)
+ (Core.result2s to_client) >>= fun () ->
begin
match m_w with
| None -> Lwt.return ()
@@ -88,7 +91,9 @@ module ADispatcher (S:STORE) = struct
>>= fun () ->
let s' = {
s with
- accepted = i
+ accepted = i;
+ cur_cli_res = None;
+ cur_cli_req = None;
} in
Lwt.return s'

0 comments on commit 093c961

Please sign in to comment.