| 833 | } |
| 834 | |
| 835 | func 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 | |
| 870 | func TestTxnDiscardBeforeCommit(t *testing.T) { |
| 871 | require.NoError(t, dg.DropAll()) |