diff --git a/internal/test_txn_10.go b/internal/test_txn_10.go index 2d4507c3..74f76e00 100644 --- a/internal/test_txn_10.go +++ b/internal/test_txn_10.go @@ -1,7 +1,10 @@ package internal import ( + "fmt" + "github.com/codecrafters-io/redis-tester/internal/redis_executable" + resp_connection "github.com/codecrafters-io/redis-tester/internal/resp/connection" resp_value "github.com/codecrafters-io/redis-tester/internal/resp/value" "github.com/codecrafters-io/redis-tester/internal/instrumented_resp_connection" @@ -18,12 +21,17 @@ func testTxErr(stageHarness *test_case_harness.TestCaseHarness) error { logger := stageHarness.Logger - client, err := instrumented_resp_connection.NewFromAddr(stageHarness, "localhost:6379", "client1") - if err != nil { - logFriendlyError(logger, err) - return err + var clients []*resp_connection.RespConnection + + for i := 0; i < 2; i++ { + client, err := instrumented_resp_connection.NewFromAddr(stageHarness, "localhost:6379", fmt.Sprintf("client-%d", i+1)) + if err != nil { + logFriendlyError(logger, err) + return err + } + clients = append(clients, client) + defer client.Close() } - defer client.Close() multiCommandTestCase := test_cases.MultiCommandTestCase{ Commands: [][]string{ @@ -36,7 +44,7 @@ func testTxErr(stageHarness *test_case_harness.TestCaseHarness) error { }, } - if err := multiCommandTestCase.RunAll(client, logger); err != nil { + if err := multiCommandTestCase.RunAll(clients[0], logger); err != nil { return err } @@ -49,5 +57,20 @@ func testTxErr(stageHarness *test_case_harness.TestCaseHarness) error { resp_value.NewErrorValue("ERR value is not an integer or out of range"), resp_value.NewIntegerValue(8)}, } - return transactionTestCase.RunAll(client, logger) + if err := transactionTestCase.RunAll(clients[0], logger); err != nil { + return err + } + + multiCommandTestCase = test_cases.MultiCommandTestCase{ + Commands: [][]string{ + {"GET", "bar"}, + {"GET", "foo"}, + }, + Assertions: []resp_assertions.RESPAssertion{ + resp_assertions.NewStringAssertion("8"), + resp_assertions.NewStringAssertion("abc"), + }, + } + + return multiCommandTestCase.RunAll(clients[1], logger) } diff --git a/internal/test_txn_11.go b/internal/test_txn_11.go index dc7d66f3..c636d282 100644 --- a/internal/test_txn_11.go +++ b/internal/test_txn_11.go @@ -1,6 +1,8 @@ package internal import ( + "fmt" + "github.com/codecrafters-io/redis-tester/internal/redis_executable" resp_connection "github.com/codecrafters-io/redis-tester/internal/resp/connection" resp_value "github.com/codecrafters-io/redis-tester/internal/resp/value" @@ -11,7 +13,7 @@ import ( "github.com/codecrafters-io/tester-utils/test_case_harness" ) -func testTxMulti(stageHarness *test_case_harness.TestCaseHarness) error { +func testTxMultiTx(stageHarness *test_case_harness.TestCaseHarness) error { b := redis_executable.NewRedisExecutable(stageHarness) if err := b.Run(); err != nil { return err @@ -22,7 +24,7 @@ func testTxMulti(stageHarness *test_case_harness.TestCaseHarness) error { var clients []*resp_connection.RespConnection for i := 0; i < 3; i++ { - client, err := instrumented_resp_connection.NewFromAddr(stageHarness, "localhost:6379", "client1") + client, err := instrumented_resp_connection.NewFromAddr(stageHarness, "localhost:6379", fmt.Sprintf("client-%d", i+1)) if err != nil { logFriendlyError(logger, err) return err diff --git a/internal/test_txn_8.go b/internal/test_txn_8.go index fd32b04d..0ee73a49 100644 --- a/internal/test_txn_8.go +++ b/internal/test_txn_8.go @@ -1,8 +1,12 @@ package internal import ( + "fmt" + "github.com/codecrafters-io/redis-tester/internal/redis_executable" + resp_connection "github.com/codecrafters-io/redis-tester/internal/resp/connection" resp_value "github.com/codecrafters-io/redis-tester/internal/resp/value" + "github.com/codecrafters-io/redis-tester/internal/resp_assertions" "github.com/codecrafters-io/redis-tester/internal/instrumented_resp_connection" "github.com/codecrafters-io/redis-tester/internal/test_cases" @@ -17,12 +21,17 @@ func testTxSuccess(stageHarness *test_case_harness.TestCaseHarness) error { logger := stageHarness.Logger - client, err := instrumented_resp_connection.NewFromAddr(stageHarness, "localhost:6379", "client1") - if err != nil { - logFriendlyError(logger, err) - return err + var clients []*resp_connection.RespConnection + + for i := 0; i < 2; i++ { + client, err := instrumented_resp_connection.NewFromAddr(stageHarness, "localhost:6379", fmt.Sprintf("client-%d", i+1)) + if err != nil { + logFriendlyError(logger, err) + return err + } + clients = append(clients, client) + defer client.Close() } - defer client.Close() transactionTestCase := test_cases.TransactionTestCase{ CommandQueue: [][]string{ @@ -34,5 +43,15 @@ func testTxSuccess(stageHarness *test_case_harness.TestCaseHarness) error { ResultArray: []resp_value.Value{resp_value.NewSimpleStringValue("OK"), resp_value.NewIntegerValue(7), resp_value.NewIntegerValue(1), resp_value.NewBulkStringValue("1")}, } - return transactionTestCase.RunAll(client, logger) + if err := transactionTestCase.RunAll(clients[0], logger); err != nil { + return err + } + + commandTestCase := test_cases.SendCommandTestCase{ + Command: "GET", + Args: []string{"foo"}, + Assertion: resp_assertions.NewStringAssertion("7"), + } + + return commandTestCase.Run(clients[1], logger) } diff --git a/internal/test_txn_9.go b/internal/test_txn_9.go index cda47e99..b41224cf 100644 --- a/internal/test_txn_9.go +++ b/internal/test_txn_9.go @@ -18,13 +18,23 @@ func testTxDiscard(stageHarness *test_case_harness.TestCaseHarness) error { logger := stageHarness.Logger - client, err := instrumented_resp_connection.NewFromAddr(stageHarness, "localhost:6379", "client1") + client, err := instrumented_resp_connection.NewFromAddr(stageHarness, "localhost:6379", "client") if err != nil { logFriendlyError(logger, err) return err } defer client.Close() + commandTestCase := test_cases.SendCommandTestCase{ + Command: "SET", + Args: []string{"bar", "42"}, + Assertion: resp_assertions.NewStringAssertion("OK"), + } + + if err := commandTestCase.Run(client, logger); err != nil { + return err + } + transactionTestCase := test_cases.TransactionTestCase{ CommandQueue: [][]string{ {"SET", "foo", "41"}, @@ -45,11 +55,13 @@ func testTxDiscard(stageHarness *test_case_harness.TestCaseHarness) error { Commands: [][]string{ {"DISCARD"}, {"GET", "foo"}, + {"GET", "bar"}, {"DISCARD"}, }, Assertions: []resp_assertions.RESPAssertion{ resp_assertions.NewStringAssertion("OK"), resp_assertions.NewNilAssertion(), + resp_assertions.NewStringAssertion("42"), resp_assertions.NewErrorAssertion("ERR DISCARD without MULTI"), }, } diff --git a/internal/test_txn_empty.go b/internal/test_txn_empty.go index b56b0b9c..38f1ab0e 100644 --- a/internal/test_txn_empty.go +++ b/internal/test_txn_empty.go @@ -18,7 +18,7 @@ func testTxEmpty(stageHarness *test_case_harness.TestCaseHarness) error { logger := stageHarness.Logger - client, err := instrumented_resp_connection.NewFromAddr(stageHarness, "localhost:6379", "client1") + client, err := instrumented_resp_connection.NewFromAddr(stageHarness, "localhost:6379", "client") if err != nil { logFriendlyError(logger, err) return err