-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add testTxQueue function for testing transaction queue
This commit adds the `testTxQueue` function to the internal package. The function sets up a Redis executable and creates two instrumented RESP connections. It then runs a transaction test case, followed by a command test case. This new function will be used for testing the transaction queue functionality.
- Loading branch information
Showing
1 changed file
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
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" | ||
"github.com/codecrafters-io/tester-utils/test_case_harness" | ||
) | ||
|
||
func testTxQueue(stageHarness *test_case_harness.TestCaseHarness) error { | ||
b := redis_executable.NewRedisExecutable(stageHarness) | ||
if err := b.Run(); err != nil { | ||
return err | ||
} | ||
|
||
logger := stageHarness.Logger | ||
|
||
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() | ||
} | ||
|
||
transactionTestCase := test_cases.TransactionTestCase{ | ||
CommandQueue: [][]string{ | ||
{"SET", "foo", "41"}, | ||
{"INCR", "foo"}, | ||
}, | ||
ResultArray: []resp_value.Value{}, | ||
} | ||
|
||
if err := transactionTestCase.RunMulti(clients[0], logger); err != nil { | ||
return err | ||
} | ||
|
||
if err := transactionTestCase.RunQueueAll(clients[0], logger); err != nil { | ||
return err | ||
} | ||
|
||
commandTestCase := test_cases.SendCommandTestCase{ | ||
Command: "GET", | ||
Args: []string{"foo"}, | ||
Assertion: resp_assertions.NewNilAssertion(), | ||
} | ||
|
||
return commandTestCase.Run(clients[1], logger) | ||
} |