Skip to content
This repository has been archived by the owner on Mar 22, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1068 from lukaszstolarczuk/add-status-checks-in-t…
Browse files Browse the repository at this point in the history
…ests

tests: check returned statuses in iterator.seek*() calls
  • Loading branch information
lukaszstolarczuk authored May 23, 2022
2 parents 0b4bb19 + 84568b2 commit 9f7de0c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 24 deletions.
22 changes: 9 additions & 13 deletions tests/engine_scenarios/all/iterator_basic.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2020-2021, Intel Corporation */
/* Copyright 2020-2022, Intel Corporation */

/**
* Test basic methods available in iterators (sorted and unsorted engines).
Expand Down Expand Up @@ -52,7 +52,7 @@ static void write_test(pmem::kv::db &kv)

/* write only two last characters */
auto last = keys.back();
it.seek(last.first);
ASSERT_STATUS(it.seek(last.first), pmem::kv::status::OK);
auto res = it.write_range(last.second.size() - 2,
std::numeric_limits<size_t>::max());
UT_ASSERT(res.is_ok());
Expand All @@ -65,7 +65,7 @@ static void write_test(pmem::kv::db &kv)
std::string(2, 'a'));

/* write only two first characters */
it.seek(last.first);
ASSERT_STATUS(it.seek(last.first), pmem::kv::status::OK);
auto res2 = it.write_range(0, 2);
UT_ASSERT(res2.is_ok());
for (auto &c : res2.get_value())
Expand All @@ -75,7 +75,7 @@ static void write_test(pmem::kv::db &kv)
verify_value<false>(it, std::string(2, 'b') + std::string(2, 'a'));

/* write only two elements from the second position */
it.seek(last.first);
ASSERT_STATUS(it.seek(last.first), pmem::kv::status::OK);
auto res3 = it.write_range(1, 2);
UT_ASSERT(res3.is_ok());
for (auto &c : res3.get_value())
Expand All @@ -87,7 +87,7 @@ static void write_test(pmem::kv::db &kv)

/* check if a read iterator sees modifications */
auto r_it = new_iterator<true>(kv);
r_it.seek(keys.back().first);
ASSERT_STATUS(r_it.seek(keys.back().first), pmem::kv::status::OK);
verify_value<true>(r_it, "bcca");
}

Expand Down Expand Up @@ -123,7 +123,7 @@ static void write_abort_test(pmem::kv::db &kv)
for (auto &c : res.get_value())
c = 'a';

it.seek(keys.back().first);
ASSERT_STATUS(it.seek(keys.back().first), pmem::kv::status::OK);
it.commit();

verify_keys<false>(it);
Expand All @@ -134,15 +134,11 @@ static void zeroed_key_test(pmem::kv::db &kv)
auto element = pmem::kv::string_view("z\0z", 3);
UT_ASSERTeq(element.size(), 3);

auto s = kv.put(element, "val1");
ASSERT_STATUS(s, pmem::kv::status::OK);

s = kv.exists(element);
ASSERT_STATUS(s, pmem::kv::status::OK);
ASSERT_STATUS(kv.put(element, "val1"), pmem::kv::status::OK);
ASSERT_STATUS(kv.exists(element), pmem::kv::status::OK);

auto it = new_iterator<true>(kv);
s = it.seek(element);
ASSERT_STATUS(s, pmem::kv::status::OK);
ASSERT_STATUS(it.seek(element), pmem::kv::status::OK);
verify_key<true>(it, element);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/engine_scenarios/concurrent/iterator_concurrent.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2020, Intel Corporation */
/* Copyright 2020-2022, Intel Corporation */

/**
* Tests methods of iterators in the concurrent way (only iterators of concurrent
Expand Down Expand Up @@ -103,7 +103,7 @@ static void concurrent_write_abort(size_t threads_number, pmem::kv::db &kv)

auto it = new_iterator<false>(kv);
for (size_t i = thread_id / 2; i < n; i += threads_number) {
it.seek(std::to_string(i));
ASSERT_STATUS(it.seek(std::to_string(i)), pmem::kv::status::OK);
if (thread_id % 2) {
auto res = it.write_range(
10, std::numeric_limits<size_t>::max());
Expand Down
4 changes: 2 additions & 2 deletions tests/engine_scenarios/pmreorder/iterator.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2020-2021, Intel Corporation */
/* Copyright 2020-2022, Intel Corporation */

/*
* iterator.cc -- iterator pmreorder test (iterator has to support seek_to_first())
Expand All @@ -13,7 +13,7 @@ static void check_exist(pmem::kv::db &kv, const std::string &key,
const std::string &value)
{
auto it = new_iterator<true>(kv);
UT_ASSERTeq(it.seek(key), pmem::kv::status::OK);
ASSERT_STATUS(it.seek(key), pmem::kv::status::OK);

auto res = it.read_range();
UT_ASSERT(res.is_ok());
Expand Down
14 changes: 7 additions & 7 deletions tests/engine_scenarios/sorted/iterator_sorted.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2020, Intel Corporation */
/* Copyright 2020-2022, Intel Corporation */

#include "../iterator.hpp"

Expand Down Expand Up @@ -192,19 +192,19 @@ static void seek_to_first_write_test(pmem::kv::db &kv)
insert_keys(kv);

/* check if seek_to_first() will internally abort transaction */
it.seek(keys.back().first);
ASSERT_STATUS(it.seek(keys.back().first), pmem::kv::status::OK);
auto res = it.write_range();
UT_ASSERT(res.is_ok());
for (auto &c : res.get_value())
c = 'a';

it.seek_to_first();
ASSERT_STATUS(it.seek_to_first(), pmem::kv::status::OK);
it.commit();

verify_keys<false>(it);

/* write something after seek_to_first() */
it.seek_to_first();
ASSERT_STATUS(it.seek_to_first(), pmem::kv::status::OK);
auto res2 = it.write_range();
UT_ASSERT(res2.is_ok());
for (auto &c : res2.get_value())
Expand All @@ -222,19 +222,19 @@ static void seek_to_last_write_test(pmem::kv::db &kv)
insert_keys(kv);

/* check if seek_to_last will internally abort transaction */
it.seek(keys.front().first);
ASSERT_STATUS(it.seek(keys.front().first), pmem::kv::status::OK);
auto res = it.write_range();
UT_ASSERT(res.is_ok());
for (auto &c : res.get_value())
c = 'a';

it.seek_to_last();
ASSERT_STATUS(it.seek_to_last(), pmem::kv::status::OK);
it.commit();

verify_keys<false>(it);

/* write something after seek_to_last() */
it.seek_to_last();
ASSERT_STATUS(it.seek_to_last(), pmem::kv::status::OK);
auto res2 = it.write_range();
UT_ASSERT(res2.is_ok());
for (auto &c : res2.get_value())
Expand Down

0 comments on commit 9f7de0c

Please sign in to comment.