Skip to content

Commit

Permalink
Adds GET.WATCH integration test using SDK (DiceDB#1011)
Browse files Browse the repository at this point in the history
  • Loading branch information
JyotinderSingh authored Oct 8, 2024
1 parent 11ba547 commit b0c9fe5
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ require (
github.com/cespare/xxhash/v2 v2.3.0
github.com/cockroachdb/swiss v0.0.0-20240612210725-f4de07ae6964
github.com/dgryski/go-farm v0.0.0-20240924180020-3414d57e47da
github.com/dicedb/go-dice v0.0.0-20240820180649-d97f15fca831
github.com/dicedb/go-dice v0.0.0-20241008182110-fc365d560804
github.com/gobwas/glob v0.2.3
github.com/google/btree v1.1.3
github.com/google/go-cmp v0.6.0
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ github.com/dgryski/go-metro v0.0.0-20211217172704-adc40b04c140 h1:y7y0Oa6UawqTFP
github.com/dgryski/go-metro v0.0.0-20211217172704-adc40b04c140/go.mod h1:c9O8+fpSOX1DM8cPNSkX/qsBWdkD4yd2dpciOWQjpBw=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/dicedb/go-dice v0.0.0-20240820180649-d97f15fca831 h1:Cqyj9WCtoobN6++bFbDSe27q94SPwJD9Z0wmu+SDRuk=
github.com/dicedb/go-dice v0.0.0-20240820180649-d97f15fca831/go.mod h1:8+VZrr14c2LW8fW4tWZ8Bv3P2lfvlg+PpsSn5cWWuiQ=
github.com/dicedb/go-dice v0.0.0-20241008164514-476ca02cf6b9 h1:e8fYQMtzhtbY29pTM5b1V5ll11YH4DswftICadMeAJw=
github.com/dicedb/go-dice v0.0.0-20241008164514-476ca02cf6b9/go.mod h1:8+VZrr14c2LW8fW4tWZ8Bv3P2lfvlg+PpsSn5cWWuiQ=
github.com/dicedb/go-dice v0.0.0-20241008182110-fc365d560804 h1:13mgInfjInxupefIfs2rvOQgvwiGO9E6wx2+rKFEUAo=
github.com/dicedb/go-dice v0.0.0-20241008182110-fc365d560804/go.mod h1:8+VZrr14c2LW8fW4tWZ8Bv3P2lfvlg+PpsSn5cWWuiQ=
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
Expand Down
35 changes: 35 additions & 0 deletions integration_tests/commands/resp/getwatch_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
package resp

import (
"context"
"fmt"
"github.com/dicedb/dice/internal/clientio"
redis "github.com/dicedb/go-dice"
"gotest.tools/v3/assert"
"net"
"testing"
"time"
)

type WatchSubscriber struct {
client *redis.Client
watch *redis.WatchCommand
}

const getWatchKey = "getwatchkey"

type getWatchTestCase struct {
Expand Down Expand Up @@ -78,3 +85,31 @@ func TestGETWATCH(t *testing.T) {
}
}
}

func TestGETWATCHWithSDK(t *testing.T) {
publisher := getLocalSdk()
subscribers := []WatchSubscriber{{client: getLocalSdk()}, {client: getLocalSdk()}, {client: getLocalSdk()}}

channels := make([]<-chan *redis.WMessage, len(subscribers))
for i, subscriber := range subscribers {
watch := subscriber.client.WatchCommand(context.Background())
subscribers[i].watch = watch
assert.Assert(t, watch != nil)
err := watch.Watch(context.Background(), "GET", getWatchKey)
assert.NilError(t, err)
channels[i] = watch.Channel()
<-channels[i] // Get the first message
}

for _, tc := range getWatchTestCases {
err := publisher.Set(context.Background(), tc.key, tc.val, 0).Err()
assert.NilError(t, err)

for _, channel := range channels {
v := <-channel
assert.Equal(t, "GET", v.Command) // command
assert.Equal(t, "1768826704", v.Name) // Fingerprint
assert.Equal(t, tc.val, v.Data.(string)) // data
}
}
}

0 comments on commit b0c9fe5

Please sign in to comment.