MCPcopy Index your code
hub / github.com/dgraph-io/dgraph / TestConcurrentQueryMutate

Function TestConcurrentQueryMutate

dgraph/cmd/alpha/txn_test.go:835–868  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

833}
834
835func TestConcurrentQueryMutate(t *testing.T) {
836 require.NoError(t, dg.DropAll())
837 require.NoError(t, dg.SetupSchema("name: string ."))
838 txn := dg.NewTxn()
839 defer func() { require.NoError(t, txn.Discard(context.Background())) }()
840
841 // Do one query, so a new timestamp is assigned to the txn.
842 q := `{me(func: uid(0x01)) { name }}`
843 _, err := txn.Query(context.Background(), q)
844 require.NoError(t, err)
845
846 var wg sync.WaitGroup
847 wg.Add(2)
848 start := time.Now()
849 go func() {
850 defer wg.Done()
851 for time.Since(start) < 5*time.Second {
852 mu := &api.Mutation{}
853 mu.SetJson = []byte(`{"uid": "0x01", "name": "manish"}`)
854 _, err := txn.Mutate(context.Background(), mu)
855 assert.Nil(t, err)
856 }
857 }()
858
859 go func() {
860 defer wg.Done()
861 for time.Since(start) < 5*time.Second {
862 _, err := txn.Query(context.Background(), q)
863 require.NoError(t, err)
864 }
865 }()
866 wg.Wait()
867 t.Logf("Done\n")
868}
869
870func TestTxnDiscardBeforeCommit(t *testing.T) {
871 require.NoError(t, dg.DropAll())

Callers

nothing calls this directly

Calls 7

DropAllMethod · 0.80
SetupSchemaMethod · 0.80
WaitMethod · 0.80
MutateMethod · 0.65
QueryMethod · 0.45
AddMethod · 0.45
DoneMethod · 0.45

Tested by

no test coverage detected