Skip to content

Commit

Permalink
regression testing passed
Browse files Browse the repository at this point in the history
  • Loading branch information
apoorvyadav1111 committed Nov 12, 2024
1 parent c0d1677 commit 7a41798
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 61 deletions.
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ run:
test:
go test -v -race -count=1 -p=1 ./integration_tests/...

test-resp:
go test -v -race -count=1 -p=1 ./integration_tests/commands/resp

test-http:
go test -v -race -count=1 -p=1 ./integration_tests/commands/http

test-ws:
go test -v -race -count=1 -p=1 ./integration_tests/commands/websocket

test-one:
go test -v -race -count=1 --run $(TEST_FUNC) ./integration_tests/...

Expand Down
2 changes: 1 addition & 1 deletion integration_tests/commands/http/hkeys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestHKeys(t *testing.T) {
commands: []HTTPCommand{
{Command: "HKEYS", Body: map[string]interface{}{"key": "k"}},
},
expected: []interface{}{nil},
expected: []interface{}{[]interface{}{}},
},
}

Expand Down
2 changes: 1 addition & 1 deletion integration_tests/commands/resp/hexists_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestHExists(t *testing.T) {
{
name: "RESP HEXISTS operation against a key holding the wrong kind of value",
commands: []string{"SET key value", "HEXISTS key field"},
expected: []interface{}{"OK", "ERR -WRONGTYPE Operation against a key holding the wrong kind of value"},
expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"},
},
}

Expand Down
2 changes: 1 addition & 1 deletion integration_tests/commands/resp/hkeys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestHKeys(t *testing.T) {
{
name: "RESP HKEYS with key containing a non-hash value",
commands: []string{"SET key_hkeys02 field1", "HKEYS key_hkeys02"},
expected: []interface{}{"OK", "ERR -WRONGTYPE Operation against a key holding the wrong kind of value"},
expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"},
},
{
name: "RESP HKEYS with wrong number of arguments",
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/commands/resp/hvals_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestHVals(t *testing.T) {
{
name: "HVALS on wrong key type",
commands: []string{"SET hvalsKey02 field", "HVALS hvalsKey02"},
expected: []interface{}{"OK", "ERR -WRONGTYPE Operation against a key holding the wrong kind of value"},
expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"},
},
{
name: "HVALS with wrong number of arguments",
Expand Down
64 changes: 12 additions & 52 deletions internal/eval/eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3432,14 +3432,8 @@ func testEvalHSCAN(t *testing.T, store *dstore.Store) {
setup: func() {
evalHSET([]string{"hash_key", "field1", "value1", "field2", "value2"}, store)
},
input: []string{"hash_key", "0"},
newValidator: func(output interface{}) {
result := output.([]interface{})
cursor := result[0].(string)
fields := result[1].([]string)
assert.Equal(t, "0", cursor)
assert.ElementsMatch(t, []string{"field1", "value1", "field2", "value2"}, fields)
},
input: []string{"hash_key", "0"},
migratedOutput: EvalResponse{Result: []interface{}{"0", []string{"field1", "value1", "field2", "value2"}}, Error: nil},
},
"HSCAN with cursor at the end": {
setup: func() {
Expand All @@ -3452,70 +3446,36 @@ func testEvalHSCAN(t *testing.T, store *dstore.Store) {
setup: func() {
evalHSET([]string{"hash_key", "field1", "value1", "field2", "value2"}, store)
},
input: []string{"hash_key", "0"},
newValidator: func(output interface{}) {
result := output.([]interface{})
cursor := result[0].(string)
fields := result[1].([]string)
assert.Equal(t, "0", cursor)
assert.ElementsMatch(t, []string{"field1", "value1", "field2", "value2"}, fields)
},
input: []string{"hash_key", "0"},
migratedOutput: EvalResponse{Result: []interface{}{"0", []string{"field1", "value1", "field2", "value2"}}, Error: nil},
},
"HSCAN with cursor in the middle": {
setup: func() {
evalHSET([]string{"hash_key", "field1", "value1", "field2", "value2"}, store)
},
input: []string{"hash_key", "1"},
newValidator: func(output interface{}) {
result := output.([]interface{})
cursor := result[0].(string)
fields := result[1].([]string)
assert.Equal(t, "0", cursor)
for _, field := range fields {
assert.Contains(t, []string{"field1", "value1", "field2", "value2"}, field)
}
},
input: []string{"hash_key", "1"},
migratedOutput: EvalResponse{Result: []interface{}{"0", []string{"field2", "value2"}}, Error: nil},
},
"HSCAN with MATCH argument": {
setup: func() {
evalHSET([]string{"hash_key", "field1", "value1", "field2", "value2", "field3", "value3"}, store)
},
input: []string{"hash_key", "0", "MATCH", "field[12]*"},
newValidator: func(output interface{}) {
result := output.([]interface{})
cursor := result[0].(string)
fields := result[1].([]string)
assert.Equal(t, "0", cursor)
assert.ElementsMatch(t, []string{"field1", "value1", "field2", "value2"}, fields)
},
input: []string{"hash_key", "0", "MATCH", "field[12]*"},
migratedOutput: EvalResponse{Result: []interface{}{"0", []string{"field1", "value1", "field2", "value2"}}, Error: nil},
},
"HSCAN with COUNT argument": {
setup: func() {
evalHSET([]string{"hash_key", "field1", "value1", "field2", "value2", "field3", "value3"}, store)
},
input: []string{"hash_key", "0", "COUNT", "2"},
newValidator: func(output interface{}) {
result := output.([]interface{})
cursor := result[0].(string)
assert.Equal(t, "2", cursor)
for _, fields := range result[1].([]string) {
assert.Contains(t, []string{"field1", "value1", "field2", "value2", "field3", "value3"}, fields)
}
},
input: []string{"hash_key", "0", "COUNT", "2"},
migratedOutput: EvalResponse{Result: []interface{}{"2", []string{"field1", "value1", "field2", "value2"}}, Error: nil},
},
"HSCAN with MATCH and COUNT arguments": {
setup: func() {
evalHSET([]string{"hash_key", "field1", "value1", "field2", "value2", "field3", "value3", "field4", "value4"}, store)
},
input: []string{"hash_key", "0", "MATCH", "field[13]*", "COUNT", "1"},
newValidator: func(output interface{}) {
result := output.([]interface{})
cursor := result[0].(string)
assert.Equal(t, "1", cursor)
for _, fields := range result[1].([]string) {
assert.Contains(t, []string{"field1", "value1", "field3", "value3"}, fields)
}
},
input: []string{"hash_key", "0", "MATCH", "field[13]*", "COUNT", "1"},
migratedOutput: EvalResponse{Result: []interface{}{"1", []string{"field1", "value1"}}, Error: nil},
},
"HSCAN with invalid MATCH pattern": {
setup: func() {
Expand Down
4 changes: 0 additions & 4 deletions internal/eval/hash.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package eval

import (
"fmt"

"github.com/dicedb/dice/internal/server/utils"
)

Expand Down Expand Up @@ -81,14 +79,12 @@ func (h *HashImpl) GetWithExpiry(field string) (*HashItem, bool) {
return &HashItem{}, false
}

fmt.Println(item.Expiry, uint64(utils.GetCurrentTime().UnixMilli()), item.Persist, item.Value, item.Expiry <= uint64(utils.GetCurrentTime().UnixMilli()))
// If the item has no expiry, return it
if item.IsPersistent() {
return &item, true
}
// If the item has expired, delete it
if item.Expiry <= uint64(utils.GetCurrentTime().UnixMilli()) {
fmt.Println("deleting", field)
delete(h.data, field)
return &HashItem{}, false
}
Expand Down
5 changes: 4 additions & 1 deletion internal/eval/store_eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"math"
"math/bits"
"sort"
"strconv"
"strings"

Expand Down Expand Up @@ -4365,7 +4366,9 @@ func evalHSCAN(args []string, store *dstore.Store) *EvalResponse {
}

items := hashMap.Items()

sort.Slice(items, func(i, j int) bool {
return items[i][0] < items[j][0]
})
// Scan the keys and add them to the results if they match the pattern
for i := int(cursor); i < len(items); i++ {
key := items[i][0]
Expand Down

0 comments on commit 7a41798

Please sign in to comment.