summaryrefslogtreecommitdiff
path: root/tests/storage_test.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/storage_test.c')
-rw-r--r--tests/storage_test.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/storage_test.c b/tests/storage_test.c
index 0e93ad9..0343f46 100644
--- a/tests/storage_test.c
+++ b/tests/storage_test.c
@@ -98,6 +98,40 @@ main(void)
input.content = duplicate_string("second");
CHECK(tiny_store_write(store, &input, &second_message) == TINY_STORE_OK);
CHECK(strcmp(first.message_id, second_message.message_id) < 0);
+ {
+ tiny_message_patch_t patch;
+ tiny_message_t updated;
+ tiny_metadata_t metadata = first.metadata;
+ tiny_sys_io_counters_t counters;
+ bool changed = false;
+ metadata.importance = 80;
+ memset(&patch, 0, sizeof(patch));
+ patch.metadata = &metadata;
+ patch.metadata_mask = TINY_METADATA_IMPORTANCE;
+ patch.expected_revision = 1;
+ patch.has_expected_revision = true;
+ tiny_message_init(&updated);
+ tiny_sys_io_counters_reset();
+ CHECK(tiny_store_update(store, first.message_id, &patch, &updated, &changed) == TINY_STORE_OK);
+ tiny_sys_io_counters_get(&counters);
+ CHECK(changed && updated.revision == 2 && updated.metadata.importance == 80);
+ CHECK(counters.flush_calls == 1 && counters.write_calls == 2);
+ CHECK(counters.write_bytes < 8192);
+ tiny_message_free(&updated);
+
+ patch.expected_revision = 2;
+ changed = true;
+ tiny_sys_io_counters_reset();
+ CHECK(tiny_store_update(store, first.message_id, &patch, &updated, &changed) == TINY_STORE_OK);
+ tiny_sys_io_counters_get(&counters);
+ CHECK(!changed && counters.write_bytes == 0 && counters.write_calls == 0
+ && counters.flush_calls == 0);
+ tiny_message_free(&updated);
+
+ patch.expected_revision = 1;
+ CHECK(tiny_store_update(store, first.message_id, &patch, &updated, &changed)
+ == TINY_STORE_CONFLICT);
+ }
tiny_message_free(&input);
tiny_message_free(&first);
tiny_message_free(&second_message);
@@ -106,6 +140,8 @@ main(void)
CHECK(tiny_store_open(&store, directory) == TINY_STORE_OK);
CHECK(tiny_store_entry_count(store) == 2);
+ CHECK(tiny_store_entry(store, 0)->message.revision == 2);
+ CHECK(tiny_store_entry(store, 0)->message.metadata.importance == 80);
{
size_t failure_index;
bool built = false;