Skip to content

Commit

Permalink
Merge pull request #148 from codecrafters-io/CC-1208
Browse files Browse the repository at this point in the history
CC-1208: add RESP data type to received data log
  • Loading branch information
ryan-gang committed May 28, 2024
2 parents 0d508c0 + 9fcfee8 commit b1e81d9
Show file tree
Hide file tree
Showing 6 changed files with 536 additions and 531 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ func defaultCallbacks(stageHarness *test_case_harness.TestCaseHarness, logPrefix
stageHarness.Logger.Debugf("%sReceived bytes: %q", logPrefix, string(bytes))
},
AfterReadValue: func(value resp_value.Value) {
stageHarness.Logger.Debugf("%sReceived RESP value: %s", logPrefix, value.FormattedString())
valueTypeLowerCase := strings.ReplaceAll(strings.ToLower(value.Type), "_", " ")
if valueTypeLowerCase == "nil" {
valueTypeLowerCase = "null bulk string"
}
stageHarness.Logger.Debugf("%sReceived RESP %s: %s", logPrefix, valueTypeLowerCase, value.FormattedString())

},
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/resp/value/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (v *Value) FormattedString() string {
case ERROR:
return fmt.Sprintf("%q", "ERR: "+v.String())
case NIL:
return "NIL"
return "\"$-1\\r\\n\""
}

return ""
Expand Down
40 changes: 20 additions & 20 deletions internal/test_helpers/fixtures/expiry/pass
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ Debug = true
[stage-7] $ redis-cli SET apple blueberry px 100
[stage-7] Sent bytes: "*5\r\n$3\r\nSET\r\n$5\r\napple\r\n$9\r\nblueberry\r\n$2\r\npx\r\n$3\r\n100\r\n"
[stage-7] Received bytes: "+OK\r\n"
[stage-7] Received RESP value: "OK"
[stage-7] Received RESP simple string: "OK"
[stage-7] Received "OK"
[stage-7] Received OK at 02:05:03.213
[stage-7] Fetching key "apple" at 02:05:03.213 (should not be expired)
[stage-7] Received OK at 20:39:57.019
[stage-7] Fetching key "apple" at 20:39:57.019 (should not be expired)
[stage-7] $ redis-cli GET apple
[stage-7] Sent bytes: "*2\r\n$3\r\nGET\r\n$5\r\napple\r\n"
[stage-7] Received bytes: "$9\r\nblueberry\r\n"
[stage-7] Received RESP value: "blueberry"
[stage-7] Received RESP bulk string: "blueberry"
[stage-7] Received "blueberry"
[stage-7] Sleeping for 101ms
[stage-7] Fetching key "apple" at 02:05:03.316 (should be expired)
[stage-7] Fetching key "apple" at 20:39:57.122 (should be expired)
[stage-7] $ redis-cli GET apple
[stage-7] Sent bytes: "*2\r\n$3\r\nGET\r\n$5\r\napple\r\n"
[stage-7] Received bytes: "$-1\r\n"
[stage-7] Received RESP value: NIL
[stage-7] Received NIL
[stage-7] Received RESP null bulk string: "$-1\r\n"
[stage-7] Received "$-1\r\n"
[stage-7] Test passed.
[stage-7] Terminating program
[stage-7] Program terminated successfully
Expand All @@ -31,13 +31,13 @@ Debug = true
[stage-6] $ redis-cli SET blueberry raspberry
[stage-6] Sent bytes: "*3\r\n$3\r\nSET\r\n$9\r\nblueberry\r\n$9\r\nraspberry\r\n"
[stage-6] Received bytes: "+OK\r\n"
[stage-6] Received RESP value: "OK"
[stage-6] Received RESP simple string: "OK"
[stage-6] Received "OK"
[stage-6] Getting key blueberry
[stage-6] $ redis-cli GET blueberry
[stage-6] Sent bytes: "*2\r\n$3\r\nGET\r\n$9\r\nblueberry\r\n"
[stage-6] Received bytes: "$9\r\nraspberry\r\n"
[stage-6] Received RESP value: "raspberry"
[stage-6] Received RESP bulk string: "raspberry"
[stage-6] Received "raspberry"
[stage-6] Test passed.
[stage-6] Terminating program
Expand All @@ -48,7 +48,7 @@ Debug = true
[stage-5] $ redis-cli ECHO pear
[stage-5] Sent bytes: "*2\r\n$4\r\nECHO\r\n$4\r\npear\r\n"
[stage-5] Received bytes: "$4\r\npear\r\n"
[stage-5] Received RESP value: "pear"
[stage-5] Received RESP bulk string: "pear"
[stage-5] Received "pear"
[stage-5] Test passed.
[stage-5] Terminating program
Expand All @@ -59,33 +59,33 @@ Debug = true
[stage-4] client-1: $ redis-cli PING
[stage-4] client-1: Sent bytes: "*1\r\n$4\r\nPING\r\n"
[stage-4] client-1: Received bytes: "+PONG\r\n"
[stage-4] client-1: Received RESP value: "PONG"
[stage-4] client-1: Received RESP simple string: "PONG"
[stage-4] Received "PONG"
[stage-4] client-2: $ redis-cli PING
[stage-4] client-2: Sent bytes: "*1\r\n$4\r\nPING\r\n"
[stage-4] client-2: Received bytes: "+PONG\r\n"
[stage-4] client-2: Received RESP value: "PONG"
[stage-4] client-2: Received RESP simple string: "PONG"
[stage-4] Received "PONG"
[stage-4] client-1: $ redis-cli PING
[stage-4] client-1: Sent bytes: "*1\r\n$4\r\nPING\r\n"
[stage-4] client-1: Received bytes: "+PONG\r\n"
[stage-4] client-1: Received RESP value: "PONG"
[stage-4] client-1: Received RESP simple string: "PONG"
[stage-4] Received "PONG"
[stage-4] client-1: $ redis-cli PING
[stage-4] client-1: Sent bytes: "*1\r\n$4\r\nPING\r\n"
[stage-4] client-1: Received bytes: "+PONG\r\n"
[stage-4] client-1: Received RESP value: "PONG"
[stage-4] client-1: Received RESP simple string: "PONG"
[stage-4] Received "PONG"
[stage-4] client-2: $ redis-cli PING
[stage-4] client-2: Sent bytes: "*1\r\n$4\r\nPING\r\n"
[stage-4] client-2: Received bytes: "+PONG\r\n"
[stage-4] client-2: Received RESP value: "PONG"
[stage-4] client-2: Received RESP simple string: "PONG"
[stage-4] Received "PONG"
[stage-4] client-1: Success, closing connection...
[stage-4] client-3: $ redis-cli PING
[stage-4] client-3: Sent bytes: "*1\r\n$4\r\nPING\r\n"
[stage-4] client-3: Received bytes: "+PONG\r\n"
[stage-4] client-3: Received RESP value: "PONG"
[stage-4] client-3: Received RESP simple string: "PONG"
[stage-4] Received "PONG"
[stage-4] client-2: Success, closing connection...
[stage-4] client-3: Success, closing connection...
Expand All @@ -98,17 +98,17 @@ Debug = true
[stage-3] client-1: $ redis-cli PING
[stage-3] client-1: Sent bytes: "*1\r\n$4\r\nPING\r\n"
[stage-3] client-1: Received bytes: "+PONG\r\n"
[stage-3] client-1: Received RESP value: "PONG"
[stage-3] client-1: Received RESP simple string: "PONG"
[stage-3] Received "PONG"
[stage-3] client-1: $ redis-cli PING
[stage-3] client-1: Sent bytes: "*1\r\n$4\r\nPING\r\n"
[stage-3] client-1: Received bytes: "+PONG\r\n"
[stage-3] client-1: Received RESP value: "PONG"
[stage-3] client-1: Received RESP simple string: "PONG"
[stage-3] Received "PONG"
[stage-3] client-1: $ redis-cli PING
[stage-3] client-1: Sent bytes: "*1\r\n$4\r\nPING\r\n"
[stage-3] client-1: Received bytes: "+PONG\r\n"
[stage-3] client-1: Received RESP value: "PONG"
[stage-3] client-1: Received RESP simple string: "PONG"
[stage-3] Received "PONG"
[stage-3] Success, closing connection...
[stage-3] Test passed.
Expand All @@ -121,7 +121,7 @@ Debug = true
[stage-2] $ redis-cli PING
[stage-2] Sent bytes: "*1\r\n$4\r\nPING\r\n"
[stage-2] Received bytes: "+PONG\r\n"
[stage-2] Received RESP value: "PONG"
[stage-2] Received RESP simple string: "PONG"
[stage-2] Received "PONG"
[stage-2] Test passed.
[stage-2] Terminating program
Expand Down

0 comments on commit b1e81d9

Please sign in to comment.