Skip to content

Commit

Permalink
πŸš€ Enhancement to the centralised test suite
Browse files Browse the repository at this point in the history
1. Added validation βœ…
2. Clenup messages πŸ“‹
3. Added delay and setup in case of resp βœ…
  • Loading branch information
Ashwin Kulkarni authored and Ashwin Kulkarni committed Dec 3, 2024
1 parent bff9234 commit aa4dbf5
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 11 deletions.
23 changes: 23 additions & 0 deletions integration_tests/commands/tests/aggregator.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tests

import (
"fmt"
"testing"
"time"

Expand Down Expand Up @@ -64,3 +65,25 @@ func SwitchAsserts(t *testing.T, kind string, expected interface{}, actual inter
assert.ElementsMatch(t, expected, actual)
}
}

func Validate(test *Meta) bool {
// Validate test structure
if len(test.Input) != len(test.Output) {
fmt.Printf("Test %s: mismatch between number of inputs (%d) and outputs (%d)", test.Name, len(test.Input), len(test.Output))
return false
}
if len(test.Delays) > 0 && len(test.Delays) != len(test.Input) {
fmt.Printf("Test %s: mismatch between number of inputs (%d) and delays (%d)", test.Name, len(test.Input), len(test.Delays))
return false
}
if len(test.Setup) > 0 {
for _, setup := range test.Setup {
if len(setup.Input) != len(setup.Output) {
fmt.Printf("Test %s (Setup): mismatch between number of setup inputs (%d) and outputs (%d)", test.Name, len(setup.Input), len(setup.Output))
return false
}
}
}

return true
}
5 changes: 4 additions & 1 deletion integration_tests/commands/tests/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/dicedb/dice/config"
"github.com/dicedb/dice/integration_tests/commands/tests/parsers"
"github.com/dicedb/dice/integration_tests/commands/tests/servers"
"gotest.tools/v3/assert"
"github.com/stretchr/testify/assert"
)

func init() {
Expand All @@ -24,6 +24,9 @@ func TestHttpCommands(t *testing.T) {

for _, test := range allTests {
t.Run(test.Name, func(t *testing.T) {
if !Validate(&test) {
t.Fatal("Test progression failed...")
}

// Setup commands
if len(test.Setup) > 0 {
Expand Down
12 changes: 7 additions & 5 deletions integration_tests/commands/tests/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,24 @@ func TestMain(m *testing.M) {
respOpts := servers.TestServerOptions{
Port: 9738,
}
httpOpts := servers.TestServerOptions{
Port: 8083,
}

wg.Add(1)
go func() {
defer wg.Done()
servers.RunRespServer(ctx, &wg, respOpts)
}()
//TODO: run all three in paraller
//RunWebSocketServer
httpOpts := servers.TestServerOptions{
Port: 8083,
}

wg.Add(1)
go func() {
defer wg.Done()
servers.RunHTTPServer(ctx, &wg, httpOpts)
}()

//TODO: RunWebSocketServer

// Wait for the server to start
time.Sleep(2 * time.Second)

Expand Down
20 changes: 19 additions & 1 deletion integration_tests/commands/tests/resp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package tests
import (
"log"
"testing"
"time"

"github.com/dicedb/dice/config"
"github.com/dicedb/dice/integration_tests/commands/tests/parsers"
"github.com/dicedb/dice/integration_tests/commands/tests/servers"
"gotest.tools/v3/assert"
"github.com/stretchr/testify/assert"
)

func init() {
Expand All @@ -23,7 +24,24 @@ func TestRespCommands(t *testing.T) {

for _, test := range allTests {
t.Run(test.Name, func(t *testing.T) {
if !Validate(&test) {
t.Fatal("Test progression failed...")
}

if len(test.Setup) > 0 {
for _, setup := range test.Setup {
for idx, cmd := range setup.Input {
output := parsers.RespCommandExecuter(conn, cmd)
assert.Equal(t, setup.Output[idx], output)
}
}
}

for idx, cmd := range test.Input {
if len(test.Delays) > 0 {
time.Sleep(test.Delays[idx])
}

output := parsers.RespCommandExecuter(conn, cmd)
assert.Equal(t, test.Output[idx], output)
}
Expand Down
4 changes: 1 addition & 3 deletions integration_tests/commands/tests/servers/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ type HTTPCommandExecutor struct {
baseURL string
}



func NewHTTPCommandExecutor() *HTTPCommandExecutor {
return &HTTPCommandExecutor{
baseURL: "http://localhost:8083",
Expand Down Expand Up @@ -112,7 +110,7 @@ func RunHTTPServer(ctx context.Context, wg *sync.WaitGroup, opt TestServerOption
// Initialize the HTTPServer
testServer := server.NewHTTPServer(shardManager, nil)
// Inform the user that the server is starting
fmt.Println("Starting the test server on port", config.DiceConfig.HTTP.Port)
fmt.Println("Starting the test HTTP server on the port", config.DiceConfig.HTTP.Port)
shardManagerCtx, cancelShardManager := context.WithCancel(ctx)
wg.Add(1)
go func() {
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/commands/tests/servers/resp.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func RunRespServer(ctx context.Context, wg *sync.WaitGroup, opt TestServerOption
wl, _ := wal.NewNullWAL()
testServer := resp.NewServer(shardManager, ioThreadManager, cmdWatchSubscriptionChan, cmdWatchChan, gec, wl)

fmt.Println("Starting the test server on port", config.DiceConfig.RespServer.Port)
fmt.Println("Starting the test RESP server on the port", config.DiceConfig.RespServer.Port)

shardManagerCtx, cancelShardManager := context.WithCancel(ctx)
wg.Add(1)
Expand Down

0 comments on commit aa4dbf5

Please sign in to comment.