Updated test suites to retry connection to tcp server. Use concurrency to setup cluster in Test_Cluster suite.

This commit is contained in:
Kelvin Clement Mwinuka
2024-05-31 18:17:36 +08:00
parent c7560ce9dd
commit b48ee54228
10 changed files with 2865 additions and 1743 deletions

View File

@@ -16,16 +16,13 @@ package str_test
import (
"errors"
"fmt"
"github.com/echovault/echovault/echovault"
"github.com/echovault/echovault/internal"
"github.com/echovault/echovault/internal/config"
"github.com/echovault/echovault/internal/constants"
"github.com/tidwall/resp"
"net"
"strconv"
"strings"
"sync"
"testing"
)
@@ -49,13 +46,9 @@ func Test_String(t *testing.T) {
return
}
wg := sync.WaitGroup{}
wg.Add(1)
go func() {
wg.Done()
mockServer.Start()
}()
wg.Wait()
t.Cleanup(func() {
mockServer.ShutDown()
@@ -63,7 +56,7 @@ func Test_String(t *testing.T) {
t.Run("Test_HandleSetRange", func(t *testing.T) {
t.Parallel()
conn, err := net.Dial("tcp", fmt.Sprintf("localhost:%d", port))
conn, err := internal.GetConnection("localhost", port)
if err != nil {
t.Error(err)
return
@@ -213,7 +206,7 @@ func Test_String(t *testing.T) {
t.Run("Test_HandleStrLen", func(t *testing.T) {
t.Parallel()
conn, err := net.Dial("tcp", fmt.Sprintf("localhost:%d", port))
conn, err := internal.GetConnection("localhost", port)
if err != nil {
t.Error(err)
return
@@ -314,7 +307,7 @@ func Test_String(t *testing.T) {
t.Run("Test_HandleSubStr", func(t *testing.T) {
t.Parallel()
conn, err := net.Dial("tcp", fmt.Sprintf("localhost:%d", port))
conn, err := internal.GetConnection("localhost", port)
if err != nil {
t.Error(err)
return