From 0134f985911295f4380f7d2a6393c3fb598f1c1c Mon Sep 17 00:00:00 2001 From: William Brown Date: Jan 19 2017 05:50:05 +0000 Subject: Commit test case proving issue with the txn --- diff --git a/test/test_sds_cow.c b/test/test_sds_cow.c index ad5f2e6..2cdafb9 100644 --- a/test/test_sds_cow.c +++ b/test/test_sds_cow.c @@ -245,8 +245,18 @@ test_out_of_order_txn_close(void **state) { struct sds_bptree_transaction *wr_btxn = NULL; struct sds_bptree_transaction *ro_btxn_a = NULL; struct sds_bptree_transaction *ro_btxn_b = NULL; + struct sds_bptree_transaction *ro_btxn_c = NULL; + size_t i = 2; - // First, open a write commit, and add a few *odd* values. + // Prepare the tree. + assert_int_equal(sds_bptree_cow_wrtxn_begin(binst, &wr_btxn), SDS_SUCCESS); + for (; i <= ((SDS_BPTREE_DEFAULT_CAPACITY + 1) * 2); i+=2) { + // This needs to add enough nodes to trigger a split + assert_int_equal(sds_bptree_cow_insert(wr_btxn, (void *)i, NULL), SDS_SUCCESS); + } + assert_int_equal(sds_bptree_cow_wrtxn_commit(wr_btxn), SDS_SUCCESS); + + // First, open a write commit, and add an *odd* value. assert_int_equal(sds_bptree_cow_wrtxn_begin(binst, &wr_btxn), SDS_SUCCESS); assert_int_equal(sds_bptree_cow_insert(wr_btxn, (void *)1, NULL), SDS_SUCCESS); assert_int_equal(sds_bptree_cow_wrtxn_commit(wr_btxn), SDS_SUCCESS); @@ -256,7 +266,7 @@ test_out_of_order_txn_close(void **state) { // Second, open another write commit, add some more. assert_int_equal(sds_bptree_cow_wrtxn_begin(binst, &wr_btxn), SDS_SUCCESS); - assert_int_equal(sds_bptree_cow_insert(wr_btxn, (void *)2, NULL), SDS_SUCCESS); + assert_int_equal(sds_bptree_cow_insert(wr_btxn, (void *)i, NULL), SDS_SUCCESS); assert_int_equal(sds_bptree_cow_wrtxn_commit(wr_btxn), SDS_SUCCESS); // Now take an RO txn to it. @@ -267,16 +277,20 @@ test_out_of_order_txn_close(void **state) { assert_int_equal(sds_bptree_cow_insert(wr_btxn, (void *)3, NULL), SDS_SUCCESS); assert_int_equal(sds_bptree_cow_wrtxn_commit(wr_btxn), SDS_SUCCESS); + assert_int_equal(sds_bptree_cow_rotxn_begin(binst, &ro_btxn_c), SDS_SUCCESS); + // Now free the second txn. /* At this point, ro_btxn_b should "own" the nodes in btxn_a, because of COW */ assert_int_equal(sds_bptree_cow_rotxn_close(ro_btxn_b), SDS_SUCCESS); // Now seacch for the taken value in the FIRST txn. Node may be freed. assert_int_equal(sds_bptree_cow_search(ro_btxn_a, (void *)1), SDS_KEY_PRESENT); - assert_int_equal(sds_bptree_cow_search(ro_btxn_a, (void *)2), SDS_KEY_NOT_PRESENT); + assert_int_equal(sds_bptree_cow_search(ro_btxn_a, (void *)3), SDS_KEY_NOT_PRESENT); + assert_int_equal(sds_bptree_cow_search(ro_btxn_a, (void *)i), SDS_KEY_NOT_PRESENT); // Now close the first txn. assert_int_equal(sds_bptree_cow_rotxn_close(ro_btxn_a), SDS_SUCCESS); + assert_int_equal(sds_bptree_cow_rotxn_close(ro_btxn_c), SDS_SUCCESS); } @@ -287,6 +301,7 @@ test_out_of_order_txn_close(void **state) { int run_cow_tests (void) { const struct CMUnitTest tests[] = { + /* cmocka_unit_test(test_1_cow_init), cmocka_unit_test_setup_teardown(test_2_begin_rotxn, bptree_test_cow_setup, @@ -309,6 +324,7 @@ run_cow_tests (void) { cmocka_unit_test_setup_teardown(test_random_insert, bptree_test_cow_setup, bptree_test_cow_teardown), + */ cmocka_unit_test_setup_teardown(test_out_of_order_txn_close, bptree_test_cow_setup, bptree_test_cow_teardown),