From fbac1b3f80394607abaaba2e3b4d50b21e21a949 Mon Sep 17 00:00:00 2001 From: Akanksha Mahajan Date: Tue, 22 Dec 2020 10:29:58 -0800 Subject: [PATCH] Add tests in ASSERT_STATUS_CHECKED (#7793) Summary: add io_tracer_parser_test and prefetch_test under ASSERT_STATUS_CHECKED Pull Request resolved: https://github.com/facebook/rocksdb/pull/7793 Test Plan: ASSERT_STATUS_CHECKED=1 make check -j64 Reviewed By: jay-zhuang Differential Revision: D25673464 Pulled By: akankshamahajan15 fbshipit-source-id: 50e0b6f17160ddda206a521a7b47ee33e699a2d4 --- Makefile | 4 +++- file/prefetch_test.cc | 8 ++++---- trace_replay/io_tracer.cc | 9 +++++---- trace_replay/io_tracer.h | 2 +- trace_replay/io_tracer_test.cc | 10 +++++----- 5 files changed, 18 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index 0398ccf67..6eb3d4272 100644 --- a/Makefile +++ b/Makefile @@ -677,7 +677,9 @@ ifdef ASSERT_STATUS_CHECKED compaction_iterator_test \ compaction_job_test \ compaction_job_stats_test \ - io_tracer_test \ + io_tracer_test \ + io_tracer_parser_test \ + prefetch_test \ merge_helper_test \ memtable_list_test \ flush_job_test \ diff --git a/file/prefetch_test.cc b/file/prefetch_test.cc index 8ebf5ea13..9cd7d1949 100644 --- a/file/prefetch_test.cc +++ b/file/prefetch_test.cc @@ -109,21 +109,21 @@ TEST_P(PrefetchTest, Basic) { // create first key range WriteBatch batch; for (int i = 0; i < kNumKeys; i++) { - batch.Put(BuildKey(i), "value for range 1 key"); + ASSERT_OK(batch.Put(BuildKey(i), "value for range 1 key")); } ASSERT_OK(db_->Write(WriteOptions(), &batch)); // create second key range batch.Clear(); for (int i = 0; i < kNumKeys; i++) { - batch.Put(BuildKey(i, "key2"), "value for range 2 key"); + ASSERT_OK(batch.Put(BuildKey(i, "key2"), "value for range 2 key")); } ASSERT_OK(db_->Write(WriteOptions(), &batch)); // delete second key range batch.Clear(); for (int i = 0; i < kNumKeys; i++) { - batch.Delete(BuildKey(i, "key2")); + ASSERT_OK(batch.Delete(BuildKey(i, "key2"))); } ASSERT_OK(db_->Write(WriteOptions(), &batch)); @@ -134,7 +134,7 @@ TEST_P(PrefetchTest, Basic) { Slice greatest(end_key.data(), end_key.size()); // commenting out the line below causes the example to work correctly - db_->CompactRange(CompactRangeOptions(), &least, &greatest); + ASSERT_OK(db_->CompactRange(CompactRangeOptions(), &least, &greatest)); if (support_prefetch && !use_direct_io) { // If underline file system supports prefetch, and directIO is not enabled diff --git a/trace_replay/io_tracer.cc b/trace_replay/io_tracer.cc index b1ae8f222..ae45b1f59 100644 --- a/trace_replay/io_tracer.cc +++ b/trace_replay/io_tracer.cc @@ -215,14 +215,15 @@ void IOTracer::EndIOTrace() { tracing_enabled = false; } -Status IOTracer::WriteIOOp(const IOTraceRecord& record) { +// TODO: Return status and handle that in file_system_tracer.h +void IOTracer::WriteIOOp(const IOTraceRecord& record) { if (!writer_.load()) { - return Status::OK(); + return; } InstrumentedMutexLock lock_guard(&trace_writer_mutex_); if (!writer_.load()) { - return Status::OK(); + return; } - return writer_.load()->WriteIOOp(record); + writer_.load()->WriteIOOp(record).PermitUncheckedError(); } } // namespace ROCKSDB_NAMESPACE diff --git a/trace_replay/io_tracer.h b/trace_replay/io_tracer.h index 36be4c602..cc6d491a6 100644 --- a/trace_replay/io_tracer.h +++ b/trace_replay/io_tracer.h @@ -158,7 +158,7 @@ class IOTracer { TSAN_SUPPRESSION bool is_tracing_enabled() const { return tracing_enabled; } - Status WriteIOOp(const IOTraceRecord& record); + void WriteIOOp(const IOTraceRecord& record); private: TraceOptions trace_options_; diff --git a/trace_replay/io_tracer_test.cc b/trace_replay/io_tracer_test.cc index 3e1602ea1..cefc83899 100644 --- a/trace_replay/io_tracer_test.cc +++ b/trace_replay/io_tracer_test.cc @@ -58,7 +58,7 @@ class IOTracerTest : public testing::Test { record.file_name = kDummyFile + std::to_string(i); record.len = i; record.offset = i + 20; - ASSERT_OK(writer->WriteIOOp(record)); + EXPECT_OK(writer->WriteIOOp(record)); } } @@ -91,7 +91,7 @@ TEST_F(IOTracerTest, AtomicWrite) { &trace_writer)); IOTracer writer; ASSERT_OK(writer.StartIOTrace(env_, trace_opt, std::move(trace_writer))); - ASSERT_OK(writer.WriteIOOp(record)); + writer.WriteIOOp(record); ASSERT_OK(env_->FileExists(trace_file_path_)); } { @@ -124,7 +124,7 @@ TEST_F(IOTracerTest, AtomicWriteBeforeStartTrace) { IOTracer writer; // The record should not be written to the trace_file since StartIOTrace is // not called. - ASSERT_OK(writer.WriteIOOp(record)); + writer.WriteIOOp(record); ASSERT_OK(env_->FileExists(trace_file_path_)); } { @@ -149,11 +149,11 @@ TEST_F(IOTracerTest, AtomicNoWriteAfterEndTrace) { &trace_writer)); IOTracer writer; ASSERT_OK(writer.StartIOTrace(env_, trace_opt, std::move(trace_writer))); - ASSERT_OK(writer.WriteIOOp(record)); + writer.WriteIOOp(record); writer.EndIOTrace(); // Write the record again. This time the record should not be written since // EndIOTrace is called. - ASSERT_OK(writer.WriteIOOp(record)); + writer.WriteIOOp(record); ASSERT_OK(env_->FileExists(trace_file_path_)); } {