# Flaky tests for Stage #YD3 (Replication - ACKs with commands)

**URL:** <https://forum.codecrafters.io/t/flaky-tests-for-stage-yd3-replication-acks-with-commands/13780>\
**Category:** Challenges\
**Tags:** challenge:redis\
**Created:** [July 20, 2025, 2:52pm UTC](https://forum.codecrafters.io/t/flaky-tests-for-stage-yd3-replication-acks-with-commands/13780 "2025-07-20T14:52:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ravisumit33](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/ravisumit33/32/14119_2.png) [@ravisumit33](https://forum.codecrafters.io/u/ravisumit33)\
**Post date:** [July 20, 2025, 2:52pm UTC](https://forum.codecrafters.io/t/flaky-tests-for-stage-yd3-replication-acks-with-commands/13780/1 "2025-07-20T14:52:12Z")

</div>

This test shows flaky behaviour on my submitted source code. I don’t know whether its the platform or my code that is problematic. Below are the two types of logs during one such failed test:

**Type I:**

```auto
[tester::#YD3] Running tests for Stage #YD3 (Replication - ACKs with commands)
[tester::#YD3] Master is running on port 6379
[tester::#YD3] $ ./your_program.sh --port 6380 --replicaof "localhost 6379"
[your_program] Attaching slave to master: localhost 6379
[your_program] Connected to master server [fd=3, master=localhost:6379]
[your_program] Sent: *1
[your_program] $4
[your_program] PING
[your_program] to [fd=3]
[your_program] Server socket listening on port 6380 [fd=4]
[your_program] Waiting for clients to connect...
[tester::#YD3] [handshake] [master] Waiting for replica to initiate handshake with "PING" command
[tester::#YD3] [handshake] [master] Received ["PING"]
[tester::#YD3] [handshake] [master] Sent "PONG"
[tester::#YD3] [handshake] [master] Waiting for replica to send "REPLCONF listening-port 6380" command
[tester::#YD3] [handshake] [master] Received [
[tester::#YD3] [handshake] [master] "REPLCONF",
[tester::#YD3] [handshake] [master] "listening-port",
[tester::#YD3] [handshake] [master] "6380"
[tester::#YD3] [handshake] [master] ]
[tester::#YD3] [handshake] [master] Sent "OK"
[your_program] Received: +PONG
[your_program] from master: 3
[tester::#YD3] [handshake] [master] Waiting for replica to send "REPLCONF capa" command
[your_program] PING complete
[your_program] Sent: *3
[your_program] $8
[your_program] REPLCONF
[your_program] $14
[your_program] listening-port
[your_program] $4
[your_program] 6380
[your_program] to [fd=3]
[your_program] Received: +OK
[your_program] from master: 3
[your_program] Sent: *3
[your_program] $8
[your_program] REPLCONF
[your_program] $4
[your_program] capa
[your_program] $6
[your_program] psync2
[your_program] to [fd=3]
[tester::#YD3] [handshake] [master] Received ["REPLCONF", "capa", "psync2"]
[tester::#YD3] [handshake] [master] Sent "OK"
[tester::#YD3] [handshake] [master] Waiting for replica to send "PSYNC" command
[your_program] Received: +OK
[your_program] from master: 3
[tester::#YD3] [handshake] [master] Received ["REPLCONF", "capa", "psync2"]
[tester::#YD3] [handshake] [master] Sent "OK"
[tester::#YD3] [handshake] [master] Waiting for replica to send "PSYNC" command
[your_program] Received: +OK
[your_program] from master: 3
[your_program] Repl configured
[your_program] Sent: *3
[your_program] $5
[your_program] PSYNC
[your_program] $1
[your_program] ?
[your_program] $2
[your_program] -1
[your_program] to [fd=3]
[tester::#YD3] [handshake] [master] Received ["PSYNC", "?", "-1"]
[tester::#YD3] [handshake] [master] Sent "FULLRESYNC 75cd7bc10c49047e0d163660f3b90625b1af31dc 0"
[tester::#YD3] [handshake] [master] Sent RDB file.
[your_program] Received: +FULLRESYNC 75cd7bc10c49047e0d163660f3b90625b1af31dc 0
[your_program] from master: 3
[tester::#YD3] [test] [master] > REPLCONF GETACK *
[your_program] FULLRESYNC recieved
[your_program] Received: $88
[your_program] REDIS0011 �redis-ver7.2.0
�[your_program] redis-bits�@�ctime��used-mem°�aof-base���n;���Z�*3
�[your_program] $8
[your_program] REPLCONF
[your_program] $6
[your_program] GETACK
[your_program] $1
[your_program] *
[your_program] from master [fd=3]
[your_program] Received RDB file from master [fd=3]
[your_program] Sent: *3
[your_program] $8
[your_program] REPLCONF
[your_program] $3
[your_program] ACK
[your_program] $1
[your_program] 0
[your_program] to [fd=3]
[tester::#YD3] [test] [master] Received ["REPLCONF", "ACK", "0"]
[tester::#YD3] [propagation] [master] > PING
[tester::#YD3] [test] [master] > REPLCONF GETACK *
[tester::#YD3] Received: "" (no content received)
[tester::#YD3] ^ error
[tester::#YD3] Error: Expected start of a new RESP2 value (either +, -, :, $ or *)
[tester::#YD3] Test failed (try setting 'debug: true' in your codecrafters.yml to see more details)

```

**Type II:**

```auto
[tester::#YD3] Running tests for Stage #YD3 (Replication - ACKs with commands)
[tester::#YD3] Master is running on port 6379
[tester::#YD3] $ ./your_program.sh --port 6380 --replicaof "localhost 6379"
[your_program] Attaching slave to master: localhost 6379
[your_program] Connected to master server [fd=3, master=localhost:6379]
[your_program] Sent: *1
[tester::#YD3] [handshake] [master] Waiting for replica to initiate handshake with "PING" command
[your_program] $4
[your_program] PING
[your_program] to [fd=3]
[your_program] Server socket listening on port 6380 [fd=4]
[your_program] Waiting for clients to connect...
[tester::#YD3] [handshake] [master] Received ["PING"]
[tester::#YD3] [handshake] [master] Sent "PONG"
[tester::#YD3] [handshake] [master] Waiting for replica to send "REPLCONF listening-port 6380" command
[your_program] Received: +PONG
[your_program] from master: 3
[your_program] PING complete
[your_program] Sent: *3
[your_program] $8
[your_program] REPLCONF
[your_program] $14
[your_program] listening-port
[your_program] $4
[your_program] 6380
[your_program] to [fd=3]
[tester::#YD3] [handshake] [master] Received [
[tester::#YD3] [handshake] [master] "REPLCONF",
[tester::#YD3] [handshake] [master] "listening-port",
[tester::#YD3] [handshake] [master] "6380"
[tester::#YD3] [handshake] [master] ]
[tester::#YD3] [handshake] [master] Sent "OK"
[tester::#YD3] [handshake] [master] Waiting for replica to send "REPLCONF capa" command
[your_program] Received: +OK
[your_program] from master: 3
[your_program] Sent: *3
[your_program] $8
[your_program] REPLCONF
[your_program] $4
[your_program] capa
[your_program] $6
[your_program] psync2
[your_program] to [fd=3]
[tester::#YD3] [handshake] [master] Received ["REPLCONF", "capa", "psync2"]
[tester::#YD3] [handshake] [master] Sent "OK"
[tester::#YD3] [handshake] [master] Waiting for replica to send "PSYNC" command
[your_program] psync2
[your_program] to [fd=3]
[tester::#YD3] [handshake] [master] Received ["REPLCONF", "capa", "psync2"]
[tester::#YD3] [handshake] [master] Sent "OK"
[tester::#YD3] [handshake] [master] Waiting for replica to send "PSYNC" command
[your_program] psync2
[your_program] to [fd=3]
[tester::#YD3] [handshake] [master] Received ["REPLCONF", "capa", "psync2"]
[tester::#YD3] [handshake] [master] Sent "OK"
[tester::#YD3] [handshake] [master] Waiting for replica to send "PSYNC" command
[your_program] psync2
[your_program] to [fd=3]
[tester::#YD3] [handshake] [master] Received ["REPLCONF", "capa", "psync2"]
[tester::#YD3] [handshake] [master] Sent "OK"
[tester::#YD3] [handshake] [master] Waiting for replica to send "PSYNC" command
[your_program] psync2
[your_program] to [fd=3]
[tester::#YD3] [handshake] [master] Received ["REPLCONF", "capa", "psync2"]
[tester::#YD3] [handshake] [master] Sent "OK"
[tester::#YD3] [handshake] [master] Waiting for replica to send "PSYNC" command
[your_program] Received: +OK
[your_program] from master: 3
[your_program] Repl configured
[your_program] Sent: *3
[your_program] $5
[your_program] PSYNC
[your_program] $1
[your_program] ?
[your_program] $2
[your_program] -1
[your_program] to [fd=3]
[tester::#YD3] [handshake] [master] Received ["PSYNC", "?", "-1"]
[tester::#YD3] [handshake] [master] Sent "FULLRESYNC 75cd7bc10c49047e0d163660f3b90625b1af31dc 0"
[tester::#YD3] [handshake] [master] Sent RDB file.
[tester::#YD3] [test] [master] > REPLCONF GETACK *
[your_program] Received: +FULLRESYNC 75cd7bc10c49047e0d163660f3b90625b1af31dc 0
[your_program] from master: 3
[your_program] FULLRESYNC recieved
[your_program] Received: $88
[your_program] REDIS0011 �redis-ver7.2.0
�[your_program] redis-bits�@�ctime��used-mem°�aof-base���n;���Z�*3
�[your_program] $8
[your_program] REPLCONF
[your_program] $6
[your_program] GETACK
[your_program] $1
[your_program] *
[your_program] from master [fd=3]
[your_program] Received RDB file from master [fd=3]
[your_program] Sent: *3
[your_program] $8
[your_program] REPLCONF
[your_program] $3
[your_program] ACK
[your_program] $1
[your_program] 0
[your_program] to [fd=3]
[tester::#YD3] [test] [master] Received ["REPLCONF", "ACK", "0"]
[tester::#YD3] [propagation] [master] > PING
[tester::#YD3] [test] [master] > REPLCONF GETACK *
[tester::#YD3] write tcp 127.0.0.1:6379->127.0.0.1:43784: write: broken pipe
[tester::#YD3] Test failed (try setting 'debug: true' in your codecrafters.yml to see more details)

```

---

<div class="post-metadata">

**Author:** ![ravisumit33](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/ravisumit33/32/14119_2.png) [@ravisumit33](https://forum.codecrafters.io/u/ravisumit33)\
**Post date:** [July 20, 2025, 8:09pm UTC](https://forum.codecrafters.io/t/flaky-tests-for-stage-yd3-replication-acks-with-commands/13780/3 "2025-07-20T20:09:15Z")

</div>

Figured out the cause. It was a bug in my code which was getting reproduced when multiple commands were getting read from the socket at once. Fixed it and now tests are working fine.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/3X/7/0/700657133935c15703e22c7c8870394f6e6dc27d.svg) [@system](https://forum.codecrafters.io/u/system)\
**Post date:** [July 25, 2025, 8:09pm UTC](https://forum.codecrafters.io/t/flaky-tests-for-stage-yd3-replication-acks-with-commands/13780/4 "2025-07-25T20:09:44Z")

</div>

Closed on July 25, 2025, 8:09pm UTC

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.
