diff --git a/integration_tests/commands/tests/aggregator.go b/integration_tests/commands/tests/aggregator.go index 347a83c6e..637720f47 100644 --- a/integration_tests/commands/tests/aggregator.go +++ b/integration_tests/commands/tests/aggregator.go @@ -1,6 +1,7 @@ package tests import ( + "fmt" "testing" "time" @@ -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 +} diff --git a/integration_tests/commands/tests/http_test.go b/integration_tests/commands/tests/http_test.go index e563614bc..22729aeed 100644 --- a/integration_tests/commands/tests/http_test.go +++ b/integration_tests/commands/tests/http_test.go @@ -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() { @@ -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 { diff --git a/integration_tests/commands/tests/main_test.go b/integration_tests/commands/tests/main_test.go index fd83db3cc..8efac12d3 100644 --- a/integration_tests/commands/tests/main_test.go +++ b/integration_tests/commands/tests/main_test.go @@ -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) diff --git a/integration_tests/commands/tests/resp_test.go b/integration_tests/commands/tests/resp_test.go index c5dddeed1..ca6a0a70d 100644 --- a/integration_tests/commands/tests/resp_test.go +++ b/integration_tests/commands/tests/resp_test.go @@ -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() { @@ -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) } diff --git a/integration_tests/commands/tests/servers/http.go b/integration_tests/commands/tests/servers/http.go index 9eecd553e..d9960d459 100644 --- a/integration_tests/commands/tests/servers/http.go +++ b/integration_tests/commands/tests/servers/http.go @@ -32,8 +32,6 @@ type HTTPCommandExecutor struct { baseURL string } - - func NewHTTPCommandExecutor() *HTTPCommandExecutor { return &HTTPCommandExecutor{ baseURL: "http://localhost:8083", @@ -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() { diff --git a/integration_tests/commands/tests/servers/resp.go b/integration_tests/commands/tests/servers/resp.go index 4247347b8..d02b91f11 100644 --- a/integration_tests/commands/tests/servers/resp.go +++ b/integration_tests/commands/tests/servers/resp.go @@ -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)