Skip to content

Commit 0698609

Browse files
authored
Merge pull request #177 from codecrafters-io/andy/fix
Update SendCommandTestCase and add test_flakiness
2 parents 2c3dd72 + a470512 commit 0698609

File tree

6 files changed

+361
-333
lines changed

6 files changed

+361
-333
lines changed

Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,19 @@ record_fixtures:
2929
update_tester_utils:
3030
go get -u github.com/codecrafters-io/tester-utils
3131

32+
TEST_TARGET ?= test
33+
RUNS ?= 100
34+
test_flakiness:
35+
@$(foreach i,$(shell seq 1 $(RUNS)), \
36+
echo "Running iteration $(i)/$(RUNS) of \"make $(TEST_TARGET)\"" ; \
37+
make $(TEST_TARGET) > /tmp/test ; \
38+
if [ "$$?" -ne 0 ]; then \
39+
echo "Test failed on iteration $(i)" ; \
40+
cat /tmp/test ; \
41+
exit 1 ; \
42+
fi ;\
43+
)
44+
3245
test_base_with_redis: build
3346
CODECRAFTERS_REPOSITORY_DIR=./internal/test_helpers/pass_all \
3447
CODECRAFTERS_TEST_CASES_JSON="[{\"slug\":\"jm1\",\"tester_log_prefix\":\"stage-1\",\"title\":\"Stage #1: Bind to a port\"},{\"slug\":\"rg2\",\"tester_log_prefix\":\"stage-2\",\"title\":\"Stage #2: Respond to PING\"},{\"slug\":\"wy1\",\"tester_log_prefix\":\"stage-3\",\"title\":\"Stage #3: Respond to multiple PINGs\"},{\"slug\":\"zu2\",\"tester_log_prefix\":\"stage-4\",\"title\":\"Stage #4: Handle concurrent clients\"},{\"slug\":\"qq0\",\"tester_log_prefix\":\"stage-5\",\"title\":\"Stage #5: Implement the ECHO command\"},{\"slug\":\"la7\",\"tester_log_prefix\":\"stage-6\",\"title\":\"Stage #6: Implement the SET \u0026 GET commands\"},{\"slug\":\"yz1\",\"tester_log_prefix\":\"stage-7\",\"title\":\"Stage #7: Expiry\"}]" \

internal/test_cases/send_command_test_case.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package test_cases
33
import (
44
"fmt"
55
"strings"
6+
"sync"
67
"time"
78

89
resp_client "github.com/codecrafters-io/redis-tester/internal/resp/connection"
@@ -21,6 +22,8 @@ type SendCommandTestCase struct {
2122

2223
// ReceivedResponse is set after the test case is run
2324
ReceivedResponse resp_value.Value
25+
26+
readMutex sync.Mutex
2427
}
2528

2629
func (t *SendCommandTestCase) Run(client *resp_client.RespConnection, logger *logger.Logger) error {
@@ -38,6 +41,9 @@ func (t *SendCommandTestCase) Run(client *resp_client.RespConnection, logger *lo
3841
return err
3942
}
4043

44+
t.readMutex.Lock()
45+
defer t.readMutex.Unlock()
46+
4147
value, err = client.ReadValue()
4248
if err != nil {
4349
return err
@@ -76,3 +82,11 @@ func (t *SendCommandTestCase) Run(client *resp_client.RespConnection, logger *lo
7682
logger.Successf("Received %s", value.FormattedString())
7783
return nil
7884
}
85+
86+
func (t *SendCommandTestCase) PauseReadingResponse() {
87+
t.readMutex.Lock()
88+
}
89+
90+
func (t *SendCommandTestCase) ResumeReadingResponse() {
91+
t.readMutex.Unlock()
92+
}

0 commit comments

Comments
 (0)