# Problem with a testcase in #YD3

**URL:** <https://forum.codecrafters.io/t/problem-with-a-testcase-in-yd3/3028>\
**Category:** Challenges\
**Tags:** challenge:redis\
**Created:** [November 20, 2024, 4:27pm UTC](https://forum.codecrafters.io/t/problem-with-a-testcase-in-yd3/3028 "2024-11-20T16:27:15Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![danilovict2](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/danilovict2/32/3024_2.png) [@danilovict2](https://forum.codecrafters.io/u/danilovict2)\
**Post date:** [November 20, 2024, 4:27pm UTC](https://forum.codecrafters.io/t/problem-with-a-testcase-in-yd3/3028/1 "2024-11-20T16:27:16Z")

</div>

The testcase failure logs:

```auto
[tester::#YD3] [test] master: > REPLCONF GETACK *
[tester::#YD3] Received: "" (no content received)
[tester::#YD3] ^ error

```

But when I run my code there clearly is some content. Also I’ve used “sudo tcpdump -i lo0 -X port 6379 or port 6380” to check the TCP traffic and there is also some content there. Here is the link to the repository with the code: [GitHub - danilovict2/go-redis](https://github.com/danilovict2/go-redis)

---

<div class="post-metadata">

**Author:** ![andy1li](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andy1li/32/10_2.png) [@andy1li](https://forum.codecrafters.io/u/andy1li)\
**Post date:** [November 20, 2024, 6:22pm UTC](https://forum.codecrafters.io/t/problem-with-a-testcase-in-yd3/3028/2 "2024-11-20T18:22:34Z")

</div>

I’ll take a look by the end of the week.

---

<div class="post-metadata">

**Author:** ![andy1li](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andy1li/32/10_2.png) [@andy1li](https://forum.codecrafters.io/u/andy1li)\
**Post date:** [November 24, 2024, 3:18pm UTC](https://forum.codecrafters.io/t/problem-with-a-testcase-in-yd3/3028/4 "2024-11-24T15:18:15Z")

</div>

Hi @danilovict2 , I tried running your code against the previous stages, but it’s no longer passing **Stage #YG4 (Replication - Command Processing)**.

 ![image](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/2X/7/7c1096e2a0862440435b4ac991b7db7539e7a18a.jpeg)

Suggestions:

1. Use [our CLI](https://docs.codecrafters.io/cli/installation) to test against previous stages by running:

```auto
codecrafters test --previous

```

1. Focus on fixing the early stages first, as later stages depend on them.

---

<div class="post-metadata">

**Author:** ![danilovict2](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/danilovict2/32/3024_2.png) [@danilovict2](https://forum.codecrafters.io/u/danilovict2)\
**Post date:** [November 26, 2024, 8:31pm UTC](https://forum.codecrafters.io/t/problem-with-a-testcase-in-yd3/3028/6 "2024-11-26T20:31:25Z")

</div>

> [@andy1li](#):
>
> `codecrafters test --previous`

Hi, I’ve fixed the previous tests you mentioned, but now previous tests fail on #hd5 and the current tests still mismatch the output I have with my on #hd5 are:  
[tester::#HD5] Expected command to be “set”, got “ping”  
[tester::#HD5] Test failed  
But when I test it on my own, nothing like this happens, and propagation seems to work fine as the keys are set in all the replicas.

---

<div class="post-metadata">

**Author:** ![danilovict2](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/danilovict2/32/3024_2.png) [@danilovict2](https://forum.codecrafters.io/u/danilovict2)\
**Post date:** [November 28, 2024, 7:29pm UTC](https://forum.codecrafters.io/t/problem-with-a-testcase-in-yd3/3028/9 "2024-11-28T19:29:39Z")

</div>

Test cases on this extension are very inconsistent. I’m currently stuck on stage #YD3 and last time I asked this admin or whoever the guy is told me to make previous stages pass. This, however, is impossible because every time I run the code I get different outputs from the tests. When I run

```auto
codecrafters test --previous

```

or

```auto
codecrafters test

```

Three possibilities happened so far:

1. All the tests passed but when I try to submit #YD3 or #YG4 fail
2. #YG4 fails with these errors:  
[tester::#YG4] [test] Getting key foo  
[tester::#YG4] [test] client: $ redis-cli GET foo  
[tester::#YG4] [test] Retrying… (1/5 attempts)  
[tester::#YG4] [test] client: \> GET foo  
[tester::#YG4] [test] Retrying… (2/5 attempts)  
[tester::#YG4] [test] client: \> GET foo  
[tester::#YG4] [test] Retrying… (3/5 attempts)  
[tester::#YG4] [test] client: \> GET foo  
[tester::#YG4] [test] Retrying… (4/5 attempts)  
[tester::#YG4] [test] client: \> GET foo  
[tester::#YG4] [test] Retrying… (5/5 attempts)  
[tester::#YG4] [test] client: \> GET foo  
[tester::#YG4] Expected simple string or bulk string, got NIL  
[tester::#YG4] Test failed (try setting ‘debug: true’ in your codecrafters.yml to see more details)
3. #YD3 fails with these errors:  
[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)

Of course, when I test locally everything works as expected, and when I check tcp connections they are all there. Here is the link to my github in case anyone has any solutions to this (though I’m sure it’s not my fault):

> **[danilovict2 - Overview](https://github.com/danilovict2)**
>
> danilovict2 has 19 repositories available. Follow their code on GitHub.

---

<div class="post-metadata">

**Author:** ![andy1li](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andy1li/32/10_2.png) [@andy1li](https://forum.codecrafters.io/u/andy1li)\
**Post date:** [November 29, 2024, 1:02am UTC](https://forum.codecrafters.io/t/problem-with-a-testcase-in-yd3/3028/10 "2024-11-29T01:02:52Z")

</div>

Hi @danilovict2, the issue is likely caused by race conditions, which can result in inconsistent outputs across multiple runs.

One common cause of race conditions for replicas is when handshaking with the master overlaps with accepting client connections simultaneously:

 ![image](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/2X/6/6ccb71a227363ba6a017db06c13fddf0dc4cea3d.png)

Could you try ensuring that the handshake is fully completed before accepting client connections?

Just for context, our tester is tested rigorously against the official Redis server, so the likelihood of variability originating from our tester is minimal.

---

<div class="post-metadata">

**Author:** ![wigiwee](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/wigiwee/32/3080_2.png) [@wigiwee](https://forum.codecrafters.io/u/wigiwee)\
**Post date:** [November 30, 2024, 4:54am UTC](https://forum.codecrafters.io/t/problem-with-a-testcase-in-yd3/3028/11 "2024-11-30T04:54:32Z")

</div>

i am facing the same issue,

> [@\#YG4 Command not reaching to the replica](https://forum.codecrafters.io/t/yg4-command-not-reaching-to-the-replica/3160):
>
> CodeCarfters tester output: remote: ------------------------------------------------------------------------ remote: remote: remote: \_\_\_ \_ \_\_\_ \_\_ \_ remote: / \_\_\ \_\_\_ \_\_| | \_\_\_ / \_\_\_ \_\_ \_\_ \_ / \_|| |\_ \_\_\_ \_ \_\_ \_\_\_ remote: / / / \_ \ / \_` | / _ \ / / | '__|/ _` || |\_ | \_\_|/ \_ \| '\_\_|/ \_\_| remote: / /\_\_\_| (\_) || (\_| || \_\_// /\_\_\_| | | (\_| || \_|| |\_| \_\_/| | \_\_ remote: \_\_\_\_/ \_\_\_/ \_\_,\_| \_\_\_|\_\_\_\_/|\_| \…

---

<div class="post-metadata">

**Author:** ![danilovict2](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/danilovict2/32/3024_2.png) [@danilovict2](https://forum.codecrafters.io/u/danilovict2)\
**Post date:** [November 30, 2024, 5:24pm UTC](https://forum.codecrafters.io/t/problem-with-a-testcase-in-yd3/3028/12 "2024-11-30T17:24:04Z")

</div>

> [@andy1li](#):
>
> One common cause of race conditions for replicas is when handshaking with the master overlaps with accepting client connections simultaneously

Could you enlighten me on how exactly I should do that?

---

<div class="post-metadata">

**Author:** ![andy1li](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andy1li/32/10_2.png) [@andy1li](https://forum.codecrafters.io/u/andy1li)\
**Post date:** [December 1, 2024, 1:36pm UTC](https://forum.codecrafters.io/t/problem-with-a-testcase-in-yd3/3028/13 "2024-12-01T13:36:57Z")

</div>

Sure! Just a heads-up—I’m also a beginner in Go, so take my suggestions with a grain of salt.

1. `s.connectToMaster` should NOT be run as a goroutine.
2. Once the handshake is complete, you can run the listener for the connection to the master as a goroutine.
3. Make other necessary adjustments to your code.

Feel free to post here if you get stuck.

---

<div class="post-metadata">

**Author:** ![danilovict2](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/danilovict2/32/3024_2.png) [@danilovict2](https://forum.codecrafters.io/u/danilovict2)\
**Post date:** [December 1, 2024, 3:57pm UTC](https://forum.codecrafters.io/t/problem-with-a-testcase-in-yd3/3028/14 "2024-12-01T15:57:24Z")

</div>

Tried that and it didn’t work

---

<div class="post-metadata">

**Author:** ![andy1li](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andy1li/32/10_2.png) [@andy1li](https://forum.codecrafters.io/u/andy1li)\
**Post date:** [December 4, 2024, 12:50pm UTC](https://forum.codecrafters.io/t/problem-with-a-testcase-in-yd3/3028/15 "2024-12-04T12:50:22Z")

</div>

@danilovict2 Are you still encountering the same issue, or do the logs indicate something different now?

---

<div class="post-metadata">

**Author:** ![danilovict2](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/danilovict2/32/3024_2.png) [@danilovict2](https://forum.codecrafters.io/u/danilovict2)\
**Post date:** [November 28, 2024, 7:29pm UTC](https://forum.codecrafters.io/t/problem-with-a-testcase-in-yd3/3028/16 "2024-11-28T19:29:39Z")

</div>

Test cases on this extension are very inconsistent. I’m currently stuck on stage #YD3 and last time I asked this admin or whoever the guy is told me to make previous stages pass. This, however, is impossible because every time I run the code I get different outputs from the tests. When I run

```auto
codecrafters test --previous

```

or

```auto
codecrafters test

```

Three possibilities happened so far:

1. All the tests passed but when I try to submit #YD3 or #YG4 fail
2. #YG4 fails with these errors:  
[tester::#YG4] [test] Getting key foo  
[tester::#YG4] [test] client: $ redis-cli GET foo  
[tester::#YG4] [test] Retrying… (1/5 attempts)  
[tester::#YG4] [test] client: \> GET foo  
[tester::#YG4] [test] Retrying… (2/5 attempts)  
[tester::#YG4] [test] client: \> GET foo  
[tester::#YG4] [test] Retrying… (3/5 attempts)  
[tester::#YG4] [test] client: \> GET foo  
[tester::#YG4] [test] Retrying… (4/5 attempts)  
[tester::#YG4] [test] client: \> GET foo  
[tester::#YG4] [test] Retrying… (5/5 attempts)  
[tester::#YG4] [test] client: \> GET foo  
[tester::#YG4] Expected simple string or bulk string, got NIL  
[tester::#YG4] Test failed (try setting ‘debug: true’ in your codecrafters.yml to see more details)
3. #YD3 fails with these errors:  
[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)

Of course, when I test locally everything works as expected, and when I check tcp connections they are all there. Here is the link to my github in case anyone has any solutions to this (though I’m sure it’s not my fault):

> **[danilovict2 - Overview](https://github.com/danilovict2)**
>
> danilovict2 has 19 repositories available. Follow their code on GitHub.

---

<div class="post-metadata">

**Author:** ![danilovict2](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/danilovict2/32/3024_2.png) [@danilovict2](https://forum.codecrafters.io/u/danilovict2)\
**Post date:** [December 4, 2024, 1:50pm UTC](https://forum.codecrafters.io/t/problem-with-a-testcase-in-yd3/3028/17 "2024-12-04T13:50:08Z")

</div>

Still have the same issue, but I don’t have a premium so the challenge has run out for me

---

<div class="post-metadata">

**Author:** ![andy1li](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andy1li/32/10_2.png) [@andy1li](https://forum.codecrafters.io/u/andy1li)\
**Post date:** [December 15, 2024, 2:31pm UTC](https://forum.codecrafters.io/t/problem-with-a-testcase-in-yd3/3028/18 "2024-12-15T14:31:09Z")

</div>

Closing this thread due to inactivity. If you still need assistance, feel free to reopen or start a new discussion!

---

<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:** [December 20, 2024, 2:31pm UTC](https://forum.codecrafters.io/t/problem-with-a-testcase-in-yd3/3028/19 "2024-12-20T14:31:28Z")

</div>

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