diff --git a/fdbclient/include/fdbclient/TenantManagement.actor.h b/fdbclient/include/fdbclient/TenantManagement.actor.h index aea476e6ee..d4c0c3464d 100644 --- a/fdbclient/include/fdbclient/TenantManagement.actor.h +++ b/fdbclient/include/fdbclient/TenantManagement.actor.h @@ -160,15 +160,7 @@ Future createTenant(Reference db, TenantName name) { tr->set(tenantLastIdKey, TenantMapEntry::idToPrefix(tenantId)); state std::pair newTenant = wait(createTenantTransaction(tr, name, tenantId)); - if (BUGGIFY) { - throw commit_unknown_result(); - } - - wait(safeThreadFutureToFuture(tr->commit())); - - if (BUGGIFY) { - throw commit_unknown_result(); - } + wait(buggifiedCommit(tr, BUGGIFY_WITH_PROB(0.1))); TraceEvent("CreatedTenant") .detail("Tenant", name) @@ -226,16 +218,7 @@ Future deleteTenant(Reference db, TenantName name) { } wait(deleteTenantTransaction(tr, name)); - - if (BUGGIFY) { - throw commit_unknown_result(); - } - - wait(safeThreadFutureToFuture(tr->commit())); - - if (BUGGIFY) { - throw commit_unknown_result(); - } + wait(buggifiedCommit(tr, BUGGIFY_WITH_PROB(0.1))); TraceEvent("DeletedTenant").detail("Tenant", name).detail("Version", tr->getCommittedVersion()); return Void(); diff --git a/flow/include/flow/genericactors.actor.h b/flow/include/flow/genericactors.actor.h index 4955fb6212..c548ee02c3 100644 --- a/flow/include/flow/genericactors.actor.h +++ b/flow/include/flow/genericactors.actor.h @@ -1921,6 +1921,47 @@ Future forward(Future from, Promise to) { } } +ACTOR template +Future buggifiedCommit(Transaction tr, bool buggify, int maxDelayDuration = 60.0) { + state int buggifyUnknownResultPoint = 0; + state int buggifyDelayPoint = 0; + + if (buggify) { + int choice = deterministicRandom()->randomInt(1, 9); + buggifyUnknownResultPoint = choice / 3; + buggifyDelayPoint = choice % 3; + } + + // Simulate a delay before commit that could potentially trigger a timeout + if (buggifyDelayPoint == 1) { + wait(delay(deterministicRandom()->random01() * maxDelayDuration)); + } + + // Simulate an unknown result that didn't commit + if (buggifyUnknownResultPoint == 1) { + // The delay avoids a no-wait commit. + if (!BUGGIFY) { + wait(delay(0)); + } + + throw commit_unknown_result(); + } + + wait(safeThreadFutureToFuture(tr->commit())); + + // Simulate a long delay after commit that could potentially trigger a timeout + if (buggifyDelayPoint == 2) { + wait(delay(deterministicRandom()->random01() * maxDelayDuration)); + } + + // Simulate an unknown result that did commit + if (buggifyUnknownResultPoint == 2) { + throw commit_unknown_result(); + } + + return Void(); +} + // Monad ACTOR template