Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CC-1299: Implement Transactions extension stages #154

Merged
merged 24 commits into from
Jun 14, 2024

Conversation

ryan-gang
Copy link
Contributor

This pull request includes changes related to the implementation of transactions in a Redis testing framework. The changes introduced new test cases, assertions, and modifications to existing functions. The most significant changes include the addition of new test cases for transaction handling, the creation of new assertion types, and the modification of the Value struct to include a bytes field.

New test cases and assertions:

Modifications to existing structures:

  • internal/resp/value/value.go: Modified the Value struct to include a bytes field and added a new Error method. This allows for the representation of integer and nil values as byte arrays and provides a method to retrieve the string representation of a value. [1] [2] [3]

Use MultiCommandTestCase for testTxIncr1, testTxIncr2, and testTxIncr3
This commit adds the testTxMulti function to the internal package. The function sets up a Redis executable and creates an instrumented RESP connection. It then runs a command test case using the MULTI command with no arguments, asserting that the response is "OK".
This commit adds the testTxEmpty function to the internal package. The function tests an empty transaction by running a Redis executable and executing various test cases. It includes assertions for error handling and ensures that the EXEC command without MULTI returns an error.
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.
This commit adds the `testTxExec` function to the internal package. The function sets up a Redis executable, creates an instrumented RESP connection, and runs a test case for the `EXEC` command.
…card

- Added support for multiple clients in the functions `testTxErr`, `testTxSuccess`, and `testTxDiscard`.
- Each client is created with a unique name using the format "client-{index+1}".
- The clients are stored in an array for later use.
- The clients are closed using the `Close` method before returning from the function.
This commit adds the `spawnClients` function. The `spawnClients` function is responsible for creating a specified number of client connections to a given address. It takes in the number of clients, address, stage harness, and logger as parameters. The function creates the clients and appends them to a slice before returning it. This new function is used in multiple places throughout the codebase to create client connections.
Copy link

linear bot commented Jun 13, 2024

- Renamed the `spawnClients` function to `SpawnClients`
- Added documentation for the `SpawnClients` function, explaining its purpose and usage
- The `SpawnClients` function creates multiple clients connected to a given address using the `instrumented_resp_connection.NewFromAddr` function
- Clients are expected to be closed after use
@ryan-gang ryan-gang changed the base branch from main to CC-1299-txn June 13, 2024 09:10
This commit adds new test cases for transaction functionality. The added test cases cover various stages of transactions, including INCR, MULTI, EXEC, and more. These tests ensure that the transaction functionality is working as expected.

- Added new test cases for transaction functionality
- Covered stages such as INCR-1, INCR-2, INCR-3, MULTI, EXEC, Empty Transaction, Queueing Commands
- Ensured proper execution and handling of failed transactions
@ryan-gang ryan-gang self-assigned this Jun 13, 2024
This commit renames several files in the internal directory for better clarity and organization. The changes include renaming `test_txn_9.go` to `test_txn_discard.go`, `test_txn_11.go` to `test_txn_multi_tx.go`, `test_txn_8.go` to `test_txn_tx.go`, and `test_txn_10.go` to `test_txn_tx_failure.go`. These file name updates improve the readability and maintainability of the codebase.
- Skip execution of transaction commands
- Use `RunAll` instead of `RunMulti` and `RunQueueAll`
- Update result array for each transaction command
This commit adds the "Transactions" extension to the Redis implementation. It includes the implementation of commands such as MULTI, EXEC, DISCARD, and handling failures within transactions. The extension also introduces stages for implementing the INCR command in multiple steps.
internal/test_txn_tx.go Outdated Show resolved Hide resolved
Copy link
Member

@rohitpaulk rohitpaulk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall! Just needs randomization added in a few places

- Removed the ShouldSkipExec flag from the TransactionTestCase struct
- Renamed the RunAll method to RunWithoutExec in the TransactionTestCase struct
- Updated test_txn_discard.go, test_txn_multi.go, test_txn_multi_tx.go, and test_txn_queue.go to use the RunWithoutExec method instead of RunAll
This commit adds a new test case to the `testTxErr` function in `internal/test_txn_tx_failure.go`. The test case includes commands to set random values for two keys, and then increment those values within a transaction. The expected result is an error value indicating that the value is not an integer or out of range, followed by the incremented value. After running the transaction, there are assertions to check if the values were updated correctly.

The purpose of this change is to ensure that transactions handle errors properly and provide accurate results when dealing with non-integer values.
This commit adds a new transaction test case to the `testTxSuccess` function in `internal/test_txn_tx.go`. The test case includes commands for setting random keys with random integer values, incrementing the values, and retrieving them. The expected results are updated accordingly. Additionally, a command test case is added to verify the final value of one of the keys.
This commit adds the functionality to generate random keys for test cases in `test_txn_incr1.go`, `test_txn_incr2.go`, and `test_txn_incr3.go`. The generated keys are used in the `SET` and `INCR` commands. This change improves the flexibility and randomness of the test cases.
This commit adds new test cases to the `testTxDiscard` function in `internal/test_txn_discard.go`. The changes include:
- Importing the `fmt` package
- Generating unique keys using the `random.RandomWords` function
- Generating random integers using the `random.RandomInt` function
- Modifying the command arguments to use the generated keys and random integers
- Updating assertions to use the generated values

These changes enhance the test coverage for transaction discards.
- In test_txn_discard, changed the number of uniqueKeys generated from 3 to 2.
- In test_txn_multi_tx, updated the commands to set key2 with a random integer value and increment key1.
- Also added a comment explaining the expected result in each transaction.
- In test_txn_queue, updated the command to set a random key with a random integer value and increment it.
@ryan-gang
Copy link
Contributor Author

Updated all the tests, to use unique random keys and values.

@ryan-gang ryan-gang merged commit 6690867 into CC-1299-txn Jun 14, 2024
2 checks passed
@ryan-gang ryan-gang deleted the CC-1299-txn-stages branch June 14, 2024 08:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants