Skip to content

Commit

Permalink
test_membership: Wait for leader barrier before waiting for tx.
Browse files Browse the repository at this point in the history
Fixes:
1. Tests were no longer able to test the condition where WAL frames were
   being applied while a tx was open, because the test didn't run long
   enough.
2. A race in the tests where some systems generate a barrier while a
   barrier was active, making it difficult to wait for the right log
   entry.

Signed-off-by: Mathieu Borderé <[email protected]>
  • Loading branch information
Mathieu Borderé committed Dec 4, 2023
1 parent 956de45 commit b44b961
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions test/integration/test_membership.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,17 @@ TEST(membership,
* entry replicated from the new leader. */
test_server_client_connect(&f->servers[0], &c_transfer);
HANDSHAKE_C(&c_transfer);
last_applied = f->servers[0].dqlite->raft.last_applied;
TRANSFER(2, &c_transfer);
test_server_client_close(&f->servers[0], &c_transfer);
last_applied = f->servers[0].dqlite->raft.last_applied;

/* Wait for new leader barrier to be applied. */
await_arg.f = f;
await_arg.id = 0;
await_arg.last_applied = last_applied + 1;
AWAIT_TRUE(last_applied_cond, await_arg, 2);

/* New write tx */
SELECT(2);
HANDSHAKE;
OPEN;
Expand All @@ -223,7 +230,8 @@ TEST(membership,

await_arg.f = f;
await_arg.id = 0;
await_arg.last_applied = last_applied + 1;
/* Wait for the write tx to be applied. */
await_arg.last_applied = last_applied + 2;
AWAIT_TRUE(last_applied_cond, await_arg, 2);

return MUNIT_OK;
Expand Down Expand Up @@ -325,10 +333,17 @@ TEST(membership,
* entry replicated from the new leader. */
test_server_client_connect(&f->servers[0], &c_transfer);
HANDSHAKE_C(&c_transfer);
last_applied = f->servers[0].dqlite->raft.last_applied;
TRANSFER(2, &c_transfer);
test_server_client_close(&f->servers[0], &c_transfer);
last_applied = f->servers[0].dqlite->raft.last_applied;

/* Wait for new leader barrier to be applied. */
await_arg.f = f;
await_arg.id = 0;
await_arg.last_applied = last_applied + 1;
AWAIT_TRUE(last_applied_cond, await_arg, 2);

/* New write tx. */
SELECT(2);
HANDSHAKE;
OPEN;
Expand All @@ -337,7 +352,8 @@ TEST(membership,

await_arg.f = f;
await_arg.id = 0;
await_arg.last_applied = last_applied + 1;
/* Wait for new write tx to be applied. */
await_arg.last_applied = last_applied + 2;
AWAIT_TRUE(last_applied_cond, await_arg, 2);

/* Transfer leadership back to original node, reconnect the client and
Expand Down

0 comments on commit b44b961

Please sign in to comment.