]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
test/log: add failing unit test for reuse of bad stream
authorCasey Bodley <cbodley@redhat.com>
Mon, 29 Jan 2018 22:10:58 +0000 (17:10 -0500)
committerCasey Bodley <cbodley@redhat.com>
Mon, 29 Jan 2018 22:10:58 +0000 (17:10 -0500)
Signed-off-by: Casey Bodley <cbodley@redhat.com>
src/log/test.cc

index 36fde96eb491afbcc0a93b75a48fcdaa86676ffc..73f037191bab610a9cda91aca66a0fae154bddb0 100644 (file)
@@ -46,6 +46,35 @@ TEST(Log, Simple)
   log.stop();
 }
 
+TEST(Log, ReuseBad)
+{
+  SubsystemMap subs;
+  subs.add(1, "foo", 1, 1);
+  Log log(&subs);
+  log.start();
+  log.set_log_file("/tmp/foo");
+  log.reopen_log_file();
+
+  const int l = 0;
+  {
+    auto e = log.create_entry(l, 1);
+    auto& out = e->get_ostream();
+    out << (const char*)nullptr;
+    EXPECT_TRUE(out.bad()); // writing nullptr to a stream sets its badbit
+    log.submit_entry(e);
+  }
+  {
+    auto e = log.create_entry(l, 1);
+    auto& out = e->get_ostream();
+    EXPECT_FALSE(out.bad()); // should not see failures from previous log entry
+    out << "hello world";
+    log.submit_entry(e);
+  }
+
+  log.flush();
+  log.stop();
+}
+
 int many = 10000;
 
 TEST(Log, ManyNoGather)