Skip to content

Commit 672bca4

Browse files
Add a unit test that tests references to indexes that may have been pruned
1 parent b79dcdd commit 672bca4

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

edgraph/server_test.go

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/dgraph-io/badger/v4"
1818
"github.com/dgraph-io/dgo/v250/protos/api"
1919
"github.com/hypermodeinc/dgraph/v25/chunker"
20+
"github.com/hypermodeinc/dgraph/v25/dql"
2021
"github.com/hypermodeinc/dgraph/v25/schema"
2122
"github.com/hypermodeinc/dgraph/v25/worker"
2223
"github.com/hypermodeinc/dgraph/v25/x"
@@ -206,3 +207,82 @@ func TestGetHash(t *testing.T) {
206207
worker.Config.AclSecretKeyBytes = x.Sensitive("123456789")
207208
require.Equal(t, hex.EncodeToString(h.Sum(nil)), getHash(10, 20))
208209
}
210+
211+
func TestVerifyUniqueWithinMutationBoundsChecks(t *testing.T) {
212+
t.Run("gmuIndex out of bounds", func(t *testing.T) {
213+
qc := &queryContext{
214+
gmuList: []*dql.Mutation{
215+
{
216+
Set: []*api.NQuad{
217+
{
218+
Subject: "_:a",
219+
Predicate: "username",
220+
ObjectValue: &api.Value{
221+
Val: &api.Value_StrVal{StrVal: "user1"},
222+
},
223+
},
224+
},
225+
},
226+
},
227+
// Reference gmuList[1], which is out of bounds.
228+
uniqueVars: map[uint64]uniquePredMeta{
229+
encodeIndex(1, 0): {},
230+
},
231+
}
232+
err := verifyUniqueWithinMutation(qc)
233+
require.NoError(t, err)
234+
})
235+
236+
t.Run("rdfIndex out of bounds", func(t *testing.T) {
237+
qc := &queryContext{
238+
gmuList: []*dql.Mutation{
239+
{
240+
Set: []*api.NQuad{
241+
// Only one element at index 0.
242+
{
243+
Subject: "_:a",
244+
Predicate: "username",
245+
ObjectValue: &api.Value{
246+
Val: &api.Value_StrVal{StrVal: "user1"},
247+
},
248+
},
249+
},
250+
},
251+
},
252+
// Reference Set[1], which is out of bounds.
253+
uniqueVars: map[uint64]uniquePredMeta{
254+
encodeIndex(0, 1): {},
255+
},
256+
}
257+
err := verifyUniqueWithinMutation(qc)
258+
require.NoError(t, err)
259+
})
260+
261+
t.Run("gmuList element is nil", func(t *testing.T) {
262+
qc := &queryContext{
263+
gmuList: []*dql.Mutation{
264+
nil, // Element at index 0 is nil.
265+
},
266+
uniqueVars: map[uint64]uniquePredMeta{
267+
encodeIndex(0, 0): {},
268+
},
269+
}
270+
err := verifyUniqueWithinMutation(qc)
271+
require.NoError(t, err)
272+
})
273+
274+
t.Run("Set slice is nil", func(t *testing.T) {
275+
qc := &queryContext{
276+
gmuList: []*dql.Mutation{
277+
{
278+
Set: nil, // Set slice is nil.
279+
},
280+
},
281+
uniqueVars: map[uint64]uniquePredMeta{
282+
encodeIndex(0, 0): {},
283+
},
284+
}
285+
err := verifyUniqueWithinMutation(qc)
286+
require.NoError(t, err)
287+
})
288+
}

0 commit comments

Comments
 (0)