Skip to content

Commit 3f10423

Browse files
committed
CP-49045: add unit test for db_get_by_uuid when a uuid is changed
Signed-off-by: Edwin Török <edwin.torok@citrix.com>
1 parent 368e710 commit 3f10423

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

ocaml/database/database_test.ml

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,7 @@ functor
463463
(* reference which we create *)
464464
let valid_ref = "ref1" in
465465
let valid_uuid = "uuid1" in
466+
let new_uuid = "uuid2" in
466467
let invalid_ref = "foo" in
467468
let invalid_uuid = "bar" in
468469
let t =
@@ -626,6 +627,32 @@ functor
626627
"read_field_where <valid table> <valid return> <valid field> <valid \
627628
value>" ;
628629
test_invalid_where_record "read_field_where" (Client.read_field_where t) ;
630+
631+
(* before changing the UUID, the new UUID should be missing *)
632+
expect_missing_uuid "VM" new_uuid (fun () ->
633+
let (_ : string) = Client.db_get_by_uuid t "VM" new_uuid in
634+
()
635+
) ;
636+
(* change UUID, can happen during VM import *)
637+
Client.write_field t "VM" valid_ref Db_names.uuid new_uuid ;
638+
let old_uuid = valid_uuid in
639+
(* new UUID should be found *)
640+
let r = Client.db_get_by_uuid t "VM" new_uuid in
641+
if r <> valid_ref then
642+
failwith_fmt "db_get_by_uuid <new uuid>: got %s; expected %s" r
643+
valid_ref ;
644+
let r = Client.db_get_by_uuid_opt t "VM" new_uuid in
645+
( if r <> Some valid_ref then
646+
let rs = Option.value ~default:"None" r in
647+
failwith_fmt "db_get_by_uuid_opt <new uuid>: got %s; expected %s" rs
648+
valid_ref
649+
) ;
650+
(* old UUID should not be found anymore *)
651+
expect_missing_uuid "VM" old_uuid (fun () ->
652+
let (_ : string) = Client.db_get_by_uuid t "VM" old_uuid in
653+
()
654+
) ;
655+
629656
Printf.printf "write_field <invalid table>\n" ;
630657
expect_missing_tbl "Vm" (fun () ->
631658
let (_ : unit) = Client.write_field t "Vm" "" "" "" in
@@ -842,5 +869,23 @@ functor
842869
)
843870
in
844871
Printf.printf "bad sequence: %.2f calls/sec\n%!" malign_time
845-
)
872+
) ;
873+
Client.delete_row t "VM" valid_ref ;
874+
(* after deleting the row, both old and new uuid must be missing *)
875+
expect_missing_uuid "VM" new_uuid (fun () ->
876+
let (_ : string) = Client.db_get_by_uuid t "VM" new_uuid in
877+
()
878+
) ;
879+
expect_missing_uuid "VM" old_uuid (fun () ->
880+
let (_ : string) = Client.db_get_by_uuid t "VM" old_uuid in
881+
()
882+
) ;
883+
let r = Client.db_get_by_uuid_opt t "VM" old_uuid in
884+
if not (Option.is_none r) then
885+
failwith_fmt "db_get_by_uuid_opt <old uuid>: got %s; expected None"
886+
valid_ref ;
887+
let r = Client.db_get_by_uuid_opt t "VM" new_uuid in
888+
if not (Option.is_none r) then
889+
failwith_fmt "db_get_by_uuid_opt <old uuid>: got %s; expected None"
890+
valid_ref
846891
end

0 commit comments

Comments
 (0)