I do realise the challenge is unreleased, but I had been tinkering with it locally, so I thought it would be best to share my findings! Apologies if the same feels premature.
The current BlockingClientGroupTestCase
just runs the assertion as is. without waiting, which is troublesome for custom implementations, as when the server is supposed to unblock a command/client, it may take a small amount of time to synchronize and do that. If, in that time itself, this assertion is run, then we get the no content to read
error, and the whole test fails.
For example, consider the test 510
:
Here are the logs from an unlucky run:
[stage-510] Running tests for Stage #510: BLPOP-1
[stage-510] $ ./your_program.sh
[your_program] Server started at port: 6379
[your_program] [Handshake] Master role with replID: 9d075485237c4f20908e83e0a352fc41 and replOffset: 0
[your_program] [Handshake] Completed successfully
[your_program] [:33364] Accepted connection
[stage-510] client-2: $ redis-cli BLPOP banana 0
[stage-510] client-2: Sent bytes: "*3\r\n$5\r\nBLPOP\r\n$6\r\nbanana\r\n$1\r\n0\r\n"
[stage-510] client-3: $ redis-cli BLPOP banana 0
[stage-510] client-3: Sent bytes: "*3\r\n$5\r\nBLPOP\r\n$6\r\nbanana\r\n$1\r\n0\r\n"
[stage-510] client-1: $ redis-cli RPUSH banana pineapple
[stage-510] client-1: Sent bytes: "*3\r\n$5\r\nRPUSH\r\n$6\r\nbanana\r\n$9\r\npineapple\r\n"
[your_program] [:33372] Accepted connection
[your_program] [:33378] Accepted connection
[your_program] [C :33378] [735339 ms] (BLPOP, banana, 0)
[your_program] [C :33372] [735339 ms] (BLPOP, banana, 0)
[your_program] [C :33364] [735345 ms] (RPUSH, banana, pineapple)
[your_program] [C :33364] [735345 ms] Response: Int(1)
[stage-510] client-1: Received bytes: ":1\r\n"
[stage-510] client-1: Received RESP integer: 1
[stage-510] Received 1
[your_program] [C :33378] [735339 ms] Response: Arr(Bulk('banana'), Bulk('pineapple'))
[stage-510] Received: "" (no content received)
[stage-510] ^ error
[stage-510] Error: Expected start of a new RESP2 value (either +, -, :, $ or *)
[stage-510] Test failed
[stage-510] Terminating program
[your_program] [C :33378] Unexpected error: Connection reset
[your_program] [C :33364] Connection closed
As you can see here:
- My sample implementation does respond to the
RPUSH
command correctly - But before my server is able to sync the list and unblock the client that issued the
BLPOP
command, the tester runs theBlockingClientGroupTestCase
’s assertion, and thus it reads no value, and the whole thing fails. - On lucky runs, the same runs after my server is able to sync and send the value, and thus it passes.
The tester should actually fix this either by:
- Retrying the assertion if the received values are empty (a couple of times)
- Define a maximum time that the tester would allow the solutions to sync, and only run the assertions after it.