zircon/system/ulib/fs/journal/test/journal_test.cc
// Tests that when data operations fail, sync can still complete with a failed result.
Tests that when data operations fail, sync can still complete with a failed result.
Tests that when data operations fail sync can still complete with a failed result .
TEST_F(JournalTest, DataWriteFailureStillLetsSyncComplete) {
  storage::VmoBuffer buffer = registry()->InitializeBuffer(5);
  const std::vector<storage::UnbufferedOperation> operations = {
      {
          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);
  MockTransactionHandler::TransactionCallback callbacks[] = {
      [&](const std::vector<storage::BufferedOperation>& requests) {
        verifier.VerifyDataWrite(operations[0], requests);
        verifier.ExtendDataOffset(operations[0].op.length);
        return ZX_ERR_IO;
      },
  };
  std::atomic<bool> sync_done = false;
  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({operations[0]});
    auto sync_promise = journal.Sync().then(
        [&](fit::result<void, zx_status_t>& result) -> fit::result<void, zx_status_t> {
          EXPECT_STATUS(ZX_ERR_IO_REFUSED, result.error());
          sync_done = true;
          return fit::ok();
        });
    journal.schedule_task(std::move(data_promise));
    journal.schedule_task(std::move(sync_promise));
  }
  EXPECT_TRUE(sync_done);
}
TEST_F ( JournalTest , DataWriteFailureStillLetsSyncComplete ) { storage :: VmoBuffer buffer = registry ( ) -> InitializeBuffer ( 5 ) ; const std :: vector < storage :: UnbufferedOperation > operations = { { 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 ) ; MockTransactionHandler :: TransactionCallback callbacks [ ] = { [ & ] ( const std :: vector < storage :: BufferedOperation > & requests ) { verifier . VerifyDataWrite ( operations [ 0 ] , requests ) ; verifier . ExtendDataOffset ( operations [ 0 ] . op . length ) ; return ZX_ERR_IO ; } , } ; std :: atomic < bool > sync_done = false ; 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 ( { operations [ 0 ] } ) ; auto sync_promise = journal . Sync ( ) . then ( [ & ] ( fit :: result < void , zx_status_t > & result ) -> fit :: result < void , zx_status_t > { EXPECT_STATUS ( ZX_ERR_IO_REFUSED , result . error ( ) ) ; sync_done = true ; return fit :: ok ( ) ; } ) ; journal . schedule_task ( std :: move ( data_promise ) ) ; journal . schedule_task ( std :: move ( sync_promise ) ) ; } EXPECT_TRUE ( sync_done ) ; }
Tests that when data operations fail, sync can still complete with a failed result.
Tests that when data operations fail sync can still complete with a failed result .
// Validate the request, but cause it to fail.