Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
3c1ec3a
test
rohitpaulk Sep 30, 2024
176ec1b
Refactor tests by commenting out unused test cases and regex replacem…
rohitpaulk Sep 30, 2024
a14e0db
Update test workflow to run tests multiple times and log failures.
rohitpaulk Sep 30, 2024
13b99e7
Update GitHub Actions workflow with concurrency and timeout settings.
rohitpaulk Sep 30, 2024
4eefa67
Update test case to restore original StageSlugs for fetch_pass scenario.
rohitpaulk Sep 30, 2024
e5f1758
Update test workflow to exit on first failure instead of counting fai…
rohitpaulk Sep 30, 2024
f40e4d0
Update Go setup action to version 5 in GitHub workflow configuration.
rohitpaulk Sep 30, 2024
a72814c
Fix command execution in your_program.sh to redirect stderr to /dev/n…
rohitpaulk Sep 30, 2024
2d20e28
Restore commented-out test case for describe_topic_partitions_pass in…
rohitpaulk Sep 30, 2024
8daab09
Remove output redirection from kafka-server-start.sh command in your_…
rohitpaulk Sep 30, 2024
9a67a94
Increase timeout for multiple test functions to 30 seconds in tester_…
rohitpaulk Sep 30, 2024
08ce57e
Add matrix strategy for test attempts in GitHub Actions workflow.
rohitpaulk Sep 30, 2024
2a09976
Refactor test cases in stages_test.go to uncomment and organize struc…
rohitpaulk Sep 30, 2024
1beaf99
Add -failfast option to go test in Makefile for quicker test failures.
rohitpaulk Sep 30, 2024
2faf147
Add clean shutdown file creation in GenerateLogDirs function
rohitpaulk Sep 30, 2024
92d694d
Rename clean shutdown file to ".kafka_cleanshutdown" for clarity.
rohitpaulk Sep 30, 2024
dadbc7b
Redirect kafka server output to /dev/null in your_program.sh script.
rohitpaulk Sep 30, 2024
78992c8
Add logging for Kafka server start and output latest test file in CI …
rohitpaulk Sep 30, 2024
ff529d9
Add logging for the latest test file in GitHub Actions workflow
rohitpaulk Sep 30, 2024
daf54d4
Improve file listing and selection logic in GitHub Actions workflow s…
rohitpaulk Sep 30, 2024
11490c1
Add file size logging in GitHub Actions and timestamp in Kafka server…
rohitpaulk Sep 30, 2024
f348507
Add base64 and raw output for latest file in test workflow script
rohitpaulk Sep 30, 2024
60ee3e1
Add cleanup function with EXIT trap to your_program.sh for better res…
rohitpaulk Sep 30, 2024
f2138a6
Update script to use shared memory path instead of temporary file path.
rohitpaulk Sep 30, 2024
511000e
Update test workflow to use /dev/shm instead of /tmp for test file ha…
rohitpaulk Sep 30, 2024
5c71df2
Add check for port 9092 binding status in your_program.sh
rohitpaulk Sep 30, 2024
698cbe3
Refactor logging in your_program.sh to improve clarity and maintainab…
rohitpaulk Sep 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 45 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
name: Test

on: push
on: [push]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 10
strategy:
matrix:
attempt: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
fail-fast: true
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v1
uses: actions/setup-go@v5
with:
go-version: 1.22.x

Expand All @@ -24,12 +33,42 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: '3.9'
python-version: "3.9"

- name: Run tests
run: make test

- if: always()
run: |
# List files in /dev/shm directory that start with "test-"
echo "Files in /dev/shm:"
ls -la /dev/shm | grep "test-"
echo ""
latest_file=$(ls /dev/shm/test-* | sort | tail -n1)
echo "Latest file: $latest_file"

# Check if a file was found
if [ -n "$latest_file" ]; then
# Print the size of the file
echo "File size: $(du -h "$latest_file" | cut -f1)"
echo ""

# Print the contents of the file
echo ""
echo "--- BASE64 ---"
echo ""
cat "$latest_file" | base64
echo ""
echo "--- RAW ---"
echo ""
cat "$latest_file"
else
echo "No test file found in /dev/shm directory"
fi

- run: make test

lint:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -42,4 +81,4 @@ jobs:
- uses: dominikh/staticcheck-action@v1.3.1
with:
version: "2024.1"
install-go: false
install-go: false
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ test_75_with_kafka: build
dist/main.out

test:
TESTER_DIR=$(shell pwd) go test -v ./internal/ --count=1
TESTER_DIR=$(shell pwd) go test -v ./internal/ -failfast --count=1

test_and_watch:
onchange '**/*' -- go test -v ./internal/
Expand Down
55 changes: 28 additions & 27 deletions internal/stages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package internal

import (
"os"
"regexp"
// "regexp"
"testing"

tester_utils_testing "github.com/codecrafters-io/tester-utils/testing"
Expand Down Expand Up @@ -46,32 +46,33 @@ func TestStages(t *testing.T) {
}

func normalizeTesterOutput(testerOutput []byte) []byte {
replacements := map[string][]*regexp.Regexp{
"hexdump": {regexp.MustCompile(`[0-9a-fA-F]{4} \| [0-9a-fA-F ]{47} \| .{0,16}`)},
"session_id": {regexp.MustCompile(`- .session_id \([0-9]{0,16}\)`)},
"leader_id": {regexp.MustCompile(`- .leader_id \([-0-9]{1,}\)`)},
"leader_epoch": {regexp.MustCompile(`- .leader_epoch \([-0-9]{1,}\)`)},
"wrote_file": {regexp.MustCompile(`- Wrote file to: .*`)},
"topic_id": {regexp.MustCompile(`- .topic_id \([0-9]{8}-[0-9]{4}-[0-9]{4}-[0-9]{4}-[0-9]{12}\)`)},
"compact_records_length": {regexp.MustCompile(`- .compact_records_length \([0-9]{2,}\)`)},
"batch_length": {regexp.MustCompile(`- .batch_length \([0-9]{2,}\)`)},
"crc": {regexp.MustCompile(`- .crc \([-0-9]{1,}\)`)},
"length": {regexp.MustCompile(`- .length \([0-9]{1,}\)`)},
"Name": {regexp.MustCompile(`✓ Topic Name: [0-9A-Za-z]{3}`)},
"UUID": {regexp.MustCompile(`✓ Topic UUID: [0-9]{8}-[0-9]{4}-[0-9]{4}-[0-9]{4}-[0-9]{12}`)},
"value_length": {regexp.MustCompile(`- .value_length \([0-9]{1,}\)`)},
"value": {regexp.MustCompile(`- .value \("[A-Za-z0-9 !]{1,}"\)`)},
"name": {regexp.MustCompile(`- .name \([A-Za-z]{1,}\)`)},
"topic_name": {regexp.MustCompile(`- .topic_name \([A-Za-z0-9 ]{1,}\)`)},
"next_cursor": {regexp.MustCompile(`- .next_cursor \(\{[A-Za-z0-9 ]{1,}\}\)`)},
"MESSAGES": {regexp.MustCompile(`✓ Messages: \["[A-Za-z !]{1,}"\]`)},
}
return []byte("empty")
// replacements := map[string][]*regexp.Regexp{
// "hexdump": {regexp.MustCompile(`[0-9a-fA-F]{4} \| [0-9a-fA-F ]{47} \| .{0,16}`)},
// "session_id": {regexp.MustCompile(`- .session_id \([0-9]{0,16}\)`)},
// "leader_id": {regexp.MustCompile(`- .leader_id \([-0-9]{1,}\)`)},
// "leader_epoch": {regexp.MustCompile(`- .leader_epoch \([-0-9]{1,}\)`)},
// "wrote_file": {regexp.MustCompile(`- Wrote file to: .*`)},
// "topic_id": {regexp.MustCompile(`- .topic_id \([0-9]{8}-[0-9]{4}-[0-9]{4}-[0-9]{4}-[0-9]{12}\)`)},
// "compact_records_length": {regexp.MustCompile(`- .compact_records_length \([0-9]{2,}\)`)},
// "batch_length": {regexp.MustCompile(`- .batch_length \([0-9]{2,}\)`)},
// "crc": {regexp.MustCompile(`- .crc \([-0-9]{1,}\)`)},
// "length": {regexp.MustCompile(`- .length \([0-9]{1,}\)`)},
// "Name": {regexp.MustCompile(`✓ Topic Name: [0-9A-Za-z]{3}`)},
// "UUID": {regexp.MustCompile(`✓ Topic UUID: [0-9]{8}-[0-9]{4}-[0-9]{4}-[0-9]{4}-[0-9]{12}`)},
// "value_length": {regexp.MustCompile(`- .value_length \([0-9]{1,}\)`)},
// "value": {regexp.MustCompile(`- .value \("[A-Za-z0-9 !]{1,}"\)`)},
// "name": {regexp.MustCompile(`- .name \([A-Za-z]{1,}\)`)},
// "topic_name": {regexp.MustCompile(`- .topic_name \([A-Za-z0-9 ]{1,}\)`)},
// "next_cursor": {regexp.MustCompile(`- .next_cursor \(\{[A-Za-z0-9 ]{1,}\}\)`)},
// "MESSAGES": {regexp.MustCompile(`✓ Messages: \["[A-Za-z !]{1,}"\]`)},
// }

for replacement, regexes := range replacements {
for _, regex := range regexes {
testerOutput = regex.ReplaceAll(testerOutput, []byte(replacement))
}
}
// for replacement, regexes := range replacements {
// for _, regex := range regexes {
// testerOutput = regex.ReplaceAll(testerOutput, []byte(replacement))
// }
// }

return testerOutput
// return testerOutput
}
25 changes: 23 additions & 2 deletions internal/test_helpers/pass_all/your_program.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,27 @@
# Get it from here: https://github.com/codecrafters-io/build-your-own-kafka/blob/main/kafka_2.13-4.0.0-SNAPSHOT.tgz
# Extract it and make sure you update the permissions
# sudo chown -R user:group ./kafka-latest
SCRIPT_DIR=$(dirname "$(realpath "$0")")
shmPath="/dev/shm/test-$(date +%s%3N)"

/usr/local/kafka-latest/bin/kafka-server-start.sh $@ > /dev/null
if lsof -i :9092 >/dev/null 2>&1; then
echo "bound"
echo "bound" >>"$shmPath"
else
echo "not bound"
echo "not bound" >>"$shmPath"
fi

echo "ShmPath: $shmPath"
echo "Started: $(date)" >"$shmPath"

# Trap EXIT signal to ensure cleanup
trap 'cleanup' EXIT

cleanup() {
echo "Exit trapped"
echo "Cleanup finished: $(date)" >>"$shmPath"
rm -f "$shmPath"
}

/usr/local/kafka-latest/bin/kafka-server-start.sh "$@" >>"$shmPath" 2>&1
echo "Finished: $(date)" >>"$shmPath"
19 changes: 18 additions & 1 deletion internal/tester_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,75 +14,92 @@ var testerDefinition = tester_definition.TesterDefinition{
{
Slug: "vi6",
TestFunc: testBindToPort,
Timeout: 15 * time.Second,
Timeout: 30 * time.Second,
},
{
Slug: "nv3",
TestFunc: testHardcodedCorrelationId,
Timeout: 30 * time.Second,
},
{
Slug: "wa6",
TestFunc: testCorrelationId,
Timeout: 30 * time.Second,
},
{
Slug: "nc5",
TestFunc: testAPIVersionErrorCase,
Timeout: 30 * time.Second,
},
{
Slug: "pv1",
TestFunc: testAPIVersion,
Timeout: 30 * time.Second,
},
{
Slug: "nh4",
TestFunc: testSequentialRequests,
Timeout: 30 * time.Second,
},
{
Slug: "sk0",
TestFunc: testConcurrentRequests,
Timeout: 30 * time.Second,
},
{
Slug: "gs0",
TestFunc: testAPIVersionwFetchKey,
Timeout: 30 * time.Second,
},
{
Slug: "dh6",
TestFunc: testFetchWithNoTopics,
Timeout: 30 * time.Second,
},
{
Slug: "hn6",
TestFunc: testFetchWithUnkownTopicID,
Timeout: 30 * time.Second,
},
{
Slug: "cm4",
TestFunc: testFetch,
Timeout: 30 * time.Second,
},
{
Slug: "eg2",
TestFunc: testSingleFetchFromDisk,
Timeout: 30 * time.Second,
},
{
Slug: "fd8",
TestFunc: testMultiFetchFromDisk,
Timeout: 30 * time.Second,
},
{
Slug: "yk1",
TestFunc: testAPIVersionwDescribeTopicPartitions,
Timeout: 30 * time.Second,
},
{
Slug: "vt6",
TestFunc: testDTPartitionWithUnknownTopic,
Timeout: 30 * time.Second,
},
{
Slug: "ea7",
TestFunc: testDTPartitionWithTopicAndSinglePartition,
Timeout: 30 * time.Second,
},
{
Slug: "ku4",
TestFunc: testDTPartitionWithTopicAndMultiplePartitions2,
Timeout: 30 * time.Second,
},
{
Slug: "wq2",
TestFunc: testDTPartitionWithTopics,
Timeout: 30 * time.Second,
},
},
}
6 changes: 6 additions & 0 deletions protocol/serializer/generate_log_dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
_ "embed"
"fmt"
"os"
"path/filepath"

"github.com/codecrafters-io/kafka-tester/protocol/common"
"github.com/codecrafters-io/tester-utils/logger"
Expand Down Expand Up @@ -129,6 +130,11 @@ func GenerateLogDirs(logger *logger.Logger) error {
return err
}

cleanShutdownPath := filepath.Join(basePath, ".kafka_cleanshutdown")
if err := os.WriteFile(cleanShutdownPath, []byte("{\"version\":0,\"brokerEpoch\":10}"), 0644); err != nil {
return fmt.Errorf("could not write clean shutdown file: %w", err)
}

logger.Infof("Finished writing log files to: %s", basePath)
logger.ResetSecondaryPrefix()

Expand Down