Skip to content

Commit

Permalink
fixing minor issues
Browse files Browse the repository at this point in the history
  • Loading branch information
vinitparekh17 committed Nov 16, 2024
1 parent 4bf843c commit e553a08
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 50 deletions.
6 changes: 5 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ type network struct {
func init() {
configFilePath := filepath.Join(DefaultConfigDir, DefaultConfigName)
if err := loadDiceConfig(configFilePath); err != nil {
log.Fatalf("Failed to load configuration: %v", err)
parser := NewConfigParser()
if err := parser.ParseDefaults(DiceConfig); err != nil {
log.Fatalf("Failed to load default configurations: %v", err)
}
slog.Warn("Failed to load configuration", slog.String("error", err.Error()), slog.String("message", "Loading default configurations"))
}
}

Expand Down
98 changes: 49 additions & 49 deletions integration_tests/commands/resp/pfcountwatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ type pfcountWatchTestCase struct {
}

type pfcountWatchWithPFMergeTestCase struct {
destKey1 string
destValue1 []string
destKey2 string
destValue2 []string
result int64
destKey1 string
destValue1 []string
destKey2 string
destValue2 []string
result int64
}

const (
Expand Down Expand Up @@ -69,24 +69,24 @@ func TestPFCOUNTWATCH(t *testing.T) {

respParsers := setUpRespParsers(t, subscribers)

t.Run("Basic PFCount Operations", func(t *testing.T) {
testPFCountAdd(t, publisher, respParsers)
},
t.Run("Basic PFCount Operations", func(t *testing.T) {
testPFCountAdd(t, publisher, respParsers)
},
)

t.Run("PFCount Operations including PFMerge", func(t *testing.T) {
testPFCountMerge(t, publisher, respParsers)
},
t.Run("PFCount Operations including PFMerge", func(t *testing.T) {
testPFCountMerge(t, publisher, respParsers)
},
)
}

func setupSubscribers(count int) []net.Conn {
subscribers := make([]net.Conn, 0, count)
for i := 0; i < count; i++ {
conn := getLocalConnection()
subscribers = append(subscribers, conn)
}
return subscribers
subscribers := make([]net.Conn, 0, count)
for i := 0; i < count; i++ {
conn := getLocalConnection()
subscribers = append(subscribers, conn)
}
return subscribers
}

func setUpRespParsers(t *testing.T, subscribers []net.Conn) []*clientio.RESPParser {
Expand All @@ -111,7 +111,7 @@ func testPFCountAdd(t *testing.T, publisher net.Conn, respParsers []*clientio.RE
for _, tc := range pfcountWatchTestCases {
res := FireCommand(publisher, fmt.Sprintf("PFADD %s %s", tc.key, tc.val))
assert.Equal(t, int64(1), res)

verifyWatchResults(t, respParsers, tc.result)
}
}
Expand All @@ -122,7 +122,7 @@ func testPFCountMerge(t *testing.T, publisher net.Conn, respParsers []*clientio.
FireCommand(publisher, fmt.Sprintf("PFADD %s %s", tc.destKey1, tc.destValue1))
FireCommand(publisher, fmt.Sprintf("PFADD %s %s", tc.destKey2, tc.destValue2))
FireCommand(publisher, fmt.Sprintf("PFMERGE %s %s %s", pfcountWatchKey, tc.destKey1, tc.destKey2))

verifyWatchResults(t, respParsers, tc.result)
}
}
Expand Down Expand Up @@ -157,11 +157,11 @@ type pfcountWatchSDKTestCase struct {
}

type pfcountWatchSDKWithPFMergeTestCase struct {
destKey1 string
destValue1 []string
destKey2 string
destValue2 []string
result int64
destKey1 string
destValue1 []string
destKey2 string
destValue2 []string
result int64
}

var PFCountWatchSDKTestCases = []pfcountWatchSDKTestCase{
Expand All @@ -178,7 +178,7 @@ var pfcountWatchSDKhWithPFMergeTestCases = []pfcountWatchSDKWithPFMergeTestCase{
}

func TestPFCountWATCHWithSDK(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), defaultTimeout)
ctx, cancel := context.WithTimeout(context.Background(), defaultTimeout)
defer cancel()

publisher := getLocalSdk()
Expand All @@ -189,31 +189,31 @@ func TestPFCountWATCHWithSDK(t *testing.T) {

channels := setUpWatchChannelsSDK(t, ctx, subscribers)

t.Run("Basic PFCount Operations", func(t *testing.T) {
testPFCountAddSDK(t, ctx, channels, publisher)
},
t.Run("Basic PFCount Operations", func(t *testing.T) {
testPFCountAddSDK(t, ctx, channels, publisher)
},
)

t.Run("PFCount Operations including PFMerge", func(t *testing.T) {
testPFCountMergeSDK(t, ctx, channels, publisher)
},
t.Run("PFCount Operations including PFMerge", func(t *testing.T) {
testPFCountMergeSDK(t, ctx, channels, publisher)
},
)
}

func setupSubscribersSDK(count int) []WatchSubscriber {
subscribers := make([]WatchSubscriber, count)
for i := range subscribers {
func setupSubscribersSDK(count int) []WatchSubscriber {
subscribers := make([]WatchSubscriber, count)
for i := range subscribers {
subscribers[i].client = getLocalSdk()
}
return subscribers
}
return subscribers
}

func cleanupSubscribersSDK(subscribers []WatchSubscriber) {
for _, sub := range subscribers {
if sub.watch != nil {
sub.watch.Close()
}
}
func cleanupSubscribersSDK(subscribers []WatchSubscriber) {
for _, sub := range subscribers {
if sub.watch != nil {
sub.watch.Close()
}
}
}

func setUpWatchChannelsSDK(t *testing.T, ctx context.Context, subscribers []WatchSubscriber) []<-chan *dicedb.WatchResult {
Expand Down Expand Up @@ -253,12 +253,12 @@ func testPFCountMergeSDK(t *testing.T, ctx context.Context, channels []<-chan *d
func verifyWatchResultsSDK(t *testing.T, channels []<-chan *dicedb.WatchResult, expected int64) {
for _, channel := range channels {
select {
case v := <-channel:
assert.Equal(t, pfcountCommandSDK, v.Command) // command
assert.Equal(t, pfcountWatchFingerPrint, v.Fingerprint) // Fingerprint
assert.DeepEqual(t, expected, v.Data) // data
case <-time.After(defaultTimeout):
t.Fatal("timeout waiting for watch result")
case v := <-channel:
assert.Equal(t, pfcountCommandSDK, v.Command) // command
assert.Equal(t, pfcountWatchFingerPrint, v.Fingerprint) // Fingerprint
assert.DeepEqual(t, expected, v.Data) // data
case <-time.After(defaultTimeout):
t.Fatal("timeout waiting for watch result")
}
}
}
}

0 comments on commit e553a08

Please sign in to comment.