# Extra test cases running in kafka stage #PV1

**URL:** <https://forum.codecrafters.io/t/extra-test-cases-running-in-kafka-stage-pv1/3369>\
**Category:** Challenges\
**Tags:** challenge:kafka\
**Created:** [December 9, 2024, 5:15am UTC](https://forum.codecrafters.io/t/extra-test-cases-running-in-kafka-stage-pv1/3369 "2024-12-09T05:15:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mahendrabishnoi2](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/mahendrabishnoi2/32/3374_2.png) [@mahendrabishnoi2](https://forum.codecrafters.io/u/mahendrabishnoi2)\
**Post date:** [December 9, 2024, 5:15am UTC](https://forum.codecrafters.io/t/extra-test-cases-running-in-kafka-stage-pv1/3369/1 "2024-12-09T05:15:00Z")

</div>

I’m stuck on Stage #PV1

My code is passing tests for this stage but tester is running tests from previous stage (#NC5) again and that’s not handled in my code. Are we supposed to evolve code in a way it handles all the previous stages? Am I missing something here?

Here are my logs:

```auto
remote: [tester::#PV1] Running tests for Stage #PV1 (Handle APIVersions requests)
remote: [tester::#PV1] $ ./your_program.sh /tmp/server.properties
remote: [tester::#PV1] Connecting to broker at: localhost:9092
remote: [your_program] Logs from your program will appear here!
remote: [tester::#PV1] Connection to broker at localhost:9092 successful
remote: [tester::#PV1] Sending "ApiVersions" (version: 4) request (Correlation id: 1630436662)
remote: [tester::#PV1] Hexdump of sent "ApiVersions" request: 
remote: [tester::#PV1] Idx | Hex | ASCII
remote: [tester::#PV1] -----+-------------------------------------------------+-----------------
remote: [tester::#PV1] 0000 | 00 00 00 23 00 12 00 04 61 2e 7d 36 00 09 6b 61 | ...#....a.}6..ka
remote: [tester::#PV1] 0010 | 66 6b 61 2d 63 6c 69 00 0a 6b 61 66 6b 61 2d 63 | fka-cli..kafka-c
remote: [tester::#PV1] 0020 | 6c 69 04 30 2e 31 00 | li.0.1.
remote: [tester::#PV1] 
remote: [tester::#PV1] Hexdump of received "ApiVersions" response: 
remote: [tester::#PV1] Idx | Hex | ASCII
remote: [tester::#PV1] -----+-------------------------------------------------+-----------------
remote: [tester::#PV1] 0000 | 00 00 00 13 61 2e 7d 36 00 00 02 00 12 00 00 00 | ....a.}6........
remote: [tester::#PV1] 0010 | 0a 00 00 00 00 00 00 | .......
remote: [tester::#PV1] 
remote: [tester::#PV1] [Decoder] - .ResponseHeader
remote: [tester::#PV1] [Decoder] - .correlation_id (1630436662)
remote: [tester::#PV1] [Decoder] - .ResponseBody
remote: [tester::#PV1] [Decoder] - .error_code (0)
remote: [tester::#PV1] [Decoder] - .num_api_keys (1)
remote: [tester::#PV1] [Decoder] - .ApiKeys[0]
remote: [tester::#PV1] [Decoder] - .api_key (18)
remote: [tester::#PV1] [Decoder] - .min_version (0)
remote: [tester::#PV1] [Decoder] - .max_version (10)
remote: [tester::#PV1] [Decoder] - .TAG_BUFFER
remote: [tester::#PV1] [Decoder] - .throttle_time_ms (0)
remote: [tester::#PV1] [Decoder] - .TAG_BUFFER
remote: [tester::#PV1] ✓ Correlation ID: 1630436662
remote: [tester::#PV1] ✓ Error code: 0 (NO_ERROR)
remote: [tester::#PV1] ✓ API keys array is non-empty
remote: [tester::#PV1] ✓ API version 4 is supported for API_VERSIONS
remote: [tester::#PV1] Test passed.
remote: [tester::#PV1] Terminating program
remote: [your_program] Received data: [0 18 0 4] (1630436662)
remote: [tester::#PV1] Program terminated successfully
remote: 
remote: [tester::#NC5] Running tests for Stage #NC5 (Parse API Version)
remote: [tester::#NC5] $ ./your_program.sh /tmp/server.properties
remote: [tester::#NC5] Connecting to broker at: localhost:9092
remote: [your_program] Logs from your program will appear here!
remote: [tester::#NC5] Connection to broker at localhost:9092 successful
remote: [tester::#NC5] Sending "ApiVersions" (version: -24371) request (Correlation id: 841604514)
remote: [tester::#NC5] Hexdump of sent "ApiVersions" request: 
remote: [tester::#NC5] Idx | Hex | ASCII
remote: [tester::#NC5] -----+-------------------------------------------------+-----------------
remote: [tester::#NC5] 0000 | 00 00 00 23 00 12 a0 cd 32 29 dd a2 00 09 6b 61 | ...#....2)....ka
remote: [tester::#NC5] 0010 | 66 6b 61 2d 63 6c 69 00 0a 6b 61 66 6b 61 2d 63 | fka-cli..kafka-c
remote: [tester::#NC5] 0020 | 6c 69 04 30 2e 31 00 | li.0.1.
remote: [tester::#NC5] 
remote: [tester::#NC5] Hexdump of received "ApiVersions" response: 
remote: [tester::#NC5] Idx | Hex | ASCII
remote: [tester::#NC5] -----+-------------------------------------------------+-----------------
remote: [tester::#NC5] 0000 | 00 00 00 13 32 29 dd a2 00 00 02 00 12 00 00 00 | ....2)..........
remote: [tester::#NC5] 0010 | 0a 00 00 00 00 00 00 | .......
remote: [tester::#NC5] 
remote: [tester::#NC5] [Decoder] - .Response
remote: [tester::#NC5] [Decoder] - .message_length (19)
remote: [tester::#NC5] [Decoder] - .ResponseHeader
remote: [tester::#NC5] [Decoder] - .correlation_id (841604514)
remote: [tester::#NC5] [Decoder] - .error_code (0)
remote: [tester::#NC5] ✓ Correlation ID: 841604514
remote: [tester::#NC5] Expected Error code to be 35, got 0
remote: [tester::#NC5] Test failed
remote: [tester::#NC5] Terminating program
remote: [your_program] Received data: [0 18 160 205] (841604514)
remote: [tester::#NC5] Program terminated successfully

```

And here’s a snippet of my code:

```go
        resp := make([]byte, 23)
	// message size
	binary.BigEndian.PutUint32(resp[0:4], 19)
	copy(resp[4:8], buffer[8:12]) // correlation id

	// API Versions Response Body
	// error code
	binary.BigEndian.PutUint16(resp[8:10], 0)

	// API Versions array
	// length of array = 1 byte
	resp[10] = 0x02

	// element 1
	// api key (2 bytes), min version (2 bytes), max version (2 bytes), tag buffer (0x00) (1 byte)
	binary.BigEndian.PutUint16(resp[11:13], 18) // api key
	binary.BigEndian.PutUint16(resp[13:15], 0) // min version
	binary.BigEndian.PutUint16(resp[15:17], 10) // max version
	resp[17] = 0 // tag buffer
	binary.BigEndian.PutUint32(resp[18:], 0) // throttle time
	resp[22] = 0 // tag buffer

	_, err = conn.Write(resp)
	if err != nil {
		fmt.Println("Error writing data: ", err.Error())
		os.Exit(1)
	}

```

---

<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 9, 2024, 6:02am UTC](https://forum.codecrafters.io/t/extra-test-cases-running-in-kafka-stage-pv1/3369/2 "2024-12-09T06:02:35Z")

</div>

> Are we supposed to evolve code in a way it handles all the previous stages?

Yes, your code should be able to handle all the stages you’ve completed so far.

Feel free to ask for help if you run into any issues!

---

<div class="post-metadata">

**Author:** ![mahendrabishnoi2](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/mahendrabishnoi2/32/3374_2.png) [@mahendrabishnoi2](https://forum.codecrafters.io/u/mahendrabishnoi2)\
**Post date:** [December 9, 2024, 6:33am UTC](https://forum.codecrafters.io/t/extra-test-cases-running-in-kafka-stage-pv1/3369/3 "2024-12-09T06:33:42Z")

</div>

> [@andy1li](#):
>
> Yes, your code should be able to handle all the stages you’ve completed so far.

When we have to hardcode error code as 35 in stage 4 and error code as 0 in stage 5, how can we handle all previous stages?

---

<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 9, 2024, 7:28am UTC](https://forum.codecrafters.io/t/extra-test-cases-running-in-kafka-stage-pv1/3369/4 "2024-12-09T07:28:52Z")

</div>

Ideally, the `error_code` shouldn’t be hardcoded. The value 35 is specifically for cases where the `request_api_version` is not between 0 and 4.

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

---

<div class="post-metadata">

**Author:** ![mahendrabishnoi2](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/mahendrabishnoi2/32/3374_2.png) [@mahendrabishnoi2](https://forum.codecrafters.io/u/mahendrabishnoi2)\
**Post date:** [December 9, 2024, 2:16pm UTC](https://forum.codecrafters.io/t/extra-test-cases-running-in-kafka-stage-pv1/3369/5 "2024-12-09T14:16:45Z")

</div>

Thanks @andy1li. That explains it.

---

<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 14, 2024, 2:17pm UTC](https://forum.codecrafters.io/t/extra-test-cases-running-in-kafka-stage-pv1/3369/6 "2024-12-14T14:17:40Z")

</div>

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