zircon/system/ulib/fs/journal/test/journal_test.cc
// Tests that sync after invoking |WriteData| waits for that data to be flushed to disk.
Tests that sync after invoking |WriteData| waits for that data to be flushed to disk.
Tests that sync after invoking |WriteData| waits for that data to be flushed to disk .
TEST_F(JournalTest, SyncAfterWritingDataWaitsForData) {
  storage::VmoBuffer buffer = registry()->InitializeBuffer(1);
  const storage::UnbufferedOperation operation = {
      zx::unowned_vmo(buffer.vmo().get()),
      {
          storage::OperationType::kWrite,
          .vmo_offset = 0,
          .dev_offset = 20,
          .length = 1,
      },
  };
  JournalRequestVerifier verifier(registry()->info(), registry()->journal(),
                                  registry()->writeback(), 0);
  std::atomic<bool> data_written = false;
  std::atomic<bool> sync_called = false;
  MockTransactionHandler::TransactionCallback callbacks[] = {
      [&](const std::vector<storage::BufferedOperation>& requests) {
        EXPECT_FALSE(data_written);
        EXPECT_FALSE(sync_called);
        verifier.VerifyDataWrite(operation, requests);
        data_written = true;
        return ZX_OK;
      },
  };
  MockTransactionHandler handler(registry(), callbacks, std::size(callbacks));
  {
    Journal journal(&handler, take_info(), take_journal_buffer(), take_data_buffer(), 0,
                    Journal::Options());
    auto data_promise = journal.WriteData({operation});
    auto sync_promise = journal.Sync().and_then([&]() {
      EXPECT_TRUE(data_written);
      EXPECT_FALSE(sync_called);
      sync_called = true;
      return fit::ok();
    });
    journal.schedule_task(std::move(sync_promise));
    journal.schedule_task(std::move(data_promise));
  }
  EXPECT_TRUE(data_written);
  EXPECT_TRUE(sync_called);
}
TEST_F ( JournalTest , SyncAfterWritingDataWaitsForData ) { storage :: VmoBuffer buffer = registry ( ) -> InitializeBuffer ( 1 ) ; const storage :: UnbufferedOperation operation = { zx :: unowned_vmo ( buffer . vmo ( ) . get ( ) ) , { storage :: OperationType :: kWrite , . vmo_offset = 0 , . dev_offset = 20 , . length = 1 , } , } ; JournalRequestVerifier verifier ( registry ( ) -> info ( ) , registry ( ) -> journal ( ) , registry ( ) -> writeback ( ) , 0 ) ; std :: atomic < bool > data_written = false ; std :: atomic < bool > sync_called = false ; MockTransactionHandler :: TransactionCallback callbacks [ ] = { [ & ] ( const std :: vector < storage :: BufferedOperation > & requests ) { EXPECT_FALSE ( data_written ) ; EXPECT_FALSE ( sync_called ) ; verifier . VerifyDataWrite ( operation , requests ) ; data_written = true ; return ZX_OK ; } , } ; MockTransactionHandler handler ( registry ( ) , callbacks , std :: size ( callbacks ) ) ; { Journal journal ( & handler , take_info ( ) , take_journal_buffer ( ) , take_data_buffer ( ) , 0 , Journal :: Options ( ) ) ; auto data_promise = journal . WriteData ( { operation } ) ; auto sync_promise = journal . Sync ( ) . and_then ( [ & ] ( ) { EXPECT_TRUE ( data_written ) ; EXPECT_FALSE ( sync_called ) ; sync_called = true ; return fit :: ok ( ) ; } ) ; journal . schedule_task ( std :: move ( sync_promise ) ) ; journal . schedule_task ( std :: move ( data_promise ) ) ; } EXPECT_TRUE ( data_written ) ; EXPECT_TRUE ( sync_called ) ; }
Tests that sync after invoking |WriteData| waits for that data to be flushed to disk.
Tests that sync after invoking |WriteData| waits for that data to be flushed to disk .
// While writing the data, we expect the sync callback to be waiting. // If sync has completed, we expect the data to have been written successfully.