Skip to content

Commit

Permalink
fixup! Refactor: Streamline actor cache flush transaction usage
Browse files Browse the repository at this point in the history
  • Loading branch information
MellowYarker committed Mar 28, 2024
1 parent 079a6e1 commit e2fa4e2
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/workerd/io/actor-cache-test.c++
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,9 @@ KJ_TEST("ActorCache get-put ordering") {
auto mockGet2 = mockStorage->expectCall("getMultiple", ws)
.withParams(CAPNP(keys = ["baz"]), "stream"_kj);

// No writes will be done until our reads finish!
mockStorage->expectNoActivity(ws);

// Let's have the second read complete first.
kj::mv(mockGet2).useCallback("stream", [&](MockClient stream) {
stream.call("values", CAPNP(list = [(key = "baz", value = "987")]))
Expand All @@ -1052,6 +1055,9 @@ KJ_TEST("ActorCache get-put ordering") {
KJ_ASSERT(KJ_ASSERT_NONNULL(expectCached(test.get("bar"))) == "456");
KJ_ASSERT(KJ_ASSERT_NONNULL(expectCached(test.get("baz"))) == "987");

// Still no writes because the first read is still outstanding.
mockStorage->expectNoActivity(ws);

// Finally, have the first read complete.
kj::mv(mockGet1).useCallback("stream", [&](MockClient stream) {
stream.call("values", CAPNP(list = [(key = "bar", value = "654"),
Expand Down Expand Up @@ -1370,13 +1376,19 @@ KJ_TEST("ActorCache read retry") {
auto mockGet = mockStorage->expectCall("get", ws)
.withParams(CAPNP(key = "foo"));

// No activity because reads are outstanding.
mockStorage->expectNoActivity(ws);

// Fail out the read with a disconnect.
kj::mv(mockGet).thenThrow(KJ_EXCEPTION(DISCONNECTED, "read failed"));

// It will be retried.
auto mockGet2 = mockStorage->expectCall("get", ws)
.withParams(CAPNP(key = "foo"));

// Still no activity because of the read.
mockStorage->expectNoActivity(ws);

// Finish it.
kj::mv(mockGet2).thenReturn(CAPNP(value = "123"));

Expand Down Expand Up @@ -1447,6 +1459,9 @@ KJ_TEST("ActorCache read hard fail") {
auto mockGet = mockStorage->expectCall("get", ws)
.withParams(CAPNP(key = "foo"));

// We won't write anything until the read completes.
mockStorage->expectNoActivity(ws);

// Fail out the read with non-disconnect.
kj::mv(mockGet).thenThrow(KJ_EXCEPTION(FAILED, "read failed"));

Expand Down Expand Up @@ -1481,6 +1496,9 @@ KJ_TEST("ActorCache read cancel") {
auto mockGet = mockStorage->expectCall("get", ws)
.withParams(CAPNP(key = "foo"));

// We won't write anything until the read completes.
mockStorage->expectNoActivity(ws);

// Cancel the read.
promise = nullptr;
mockGet.expectCanceled();
Expand Down Expand Up @@ -1918,6 +1936,9 @@ KJ_TEST("ActorCache list() with seemingly-redundant dirty entries") {
auto listCall = mockStorage->expectCall("list", ws)
.withParams(CAPNP(start = "aaa", end = "fff"), "stream"_kj);

// The delete won't do any work until the list completes.
mockStorage->expectNoActivity(ws);

// Now write some contradictory values.
test.put("bbb", "bval");
KJ_ASSERT(expectCached(test.delete_("ccc")) == 1);
Expand Down Expand Up @@ -2917,6 +2938,9 @@ KJ_TEST("ActorCache listReverse() with seemingly-redundant dirty entries") {
auto listCall = mockStorage->expectCall("list", ws)
.withParams(CAPNP(start = "aaa", end = "fff", reverse = true), "stream"_kj);

// We won't do any work while the list is outstanding.
mockStorage->expectNoActivity(ws);

// Now write some contradictory values.
test.put("bbb", "bval");
KJ_ASSERT(expectCached(test.delete_("ccc")) == 1);
Expand Down

0 comments on commit e2fa4e2

Please sign in to comment.