(t *testing.T)
| 867 | } |
| 868 | |
| 869 | func TestIterateParallel(t *testing.T) { |
| 870 | key := func(account int) []byte { |
| 871 | var b [4]byte |
| 872 | binary.BigEndian.PutUint32(b[:], uint32(account)) |
| 873 | return append([]byte("account-"), b[:]...) |
| 874 | } |
| 875 | |
| 876 | N := 100000 |
| 877 | iterate := func(txn *Txn, wg *sync.WaitGroup) { |
| 878 | defer wg.Done() |
| 879 | itr := txn.NewIterator(DefaultIteratorOptions) |
| 880 | defer itr.Close() |
| 881 | |
| 882 | var count int |
| 883 | for itr.Rewind(); itr.Valid(); itr.Next() { |
| 884 | count++ |
| 885 | item := itr.Item() |
| 886 | require.Equal(t, "account-", string(item.Key()[0:8])) |
| 887 | err := item.Value(func(val []byte) error { |
| 888 | require.Equal(t, "1000", string(val)) |
| 889 | return nil |
| 890 | }) |
| 891 | require.NoError(t, err) |
| 892 | } |
| 893 | require.Equal(t, N, count) |
| 894 | itr.Close() // Double close. |
| 895 | } |
| 896 | |
| 897 | opt := DefaultOptions("") |
| 898 | runBadgerTest(t, &opt, func(t *testing.T, db *DB) { |
| 899 | var wg sync.WaitGroup |
| 900 | var txns []*Txn |
| 901 | for i := 0; i < N; i++ { |
| 902 | wg.Add(1) |
| 903 | txn := db.NewTransaction(true) |
| 904 | require.NoError(t, txn.SetEntry(NewEntry(key(i), []byte("1000")))) |
| 905 | txns = append(txns, txn) |
| 906 | } |
| 907 | for _, txn := range txns { |
| 908 | txn.CommitWith(func(err error) { |
| 909 | y.Check(err) |
| 910 | wg.Done() |
| 911 | }) |
| 912 | } |
| 913 | |
| 914 | wg.Wait() |
| 915 | |
| 916 | // Check that a RW txn can run multiple iterators. |
| 917 | txn := db.NewTransaction(true) |
| 918 | itr := txn.NewIterator(DefaultIteratorOptions) |
| 919 | require.NotPanics(t, func() { |
| 920 | // Now that multiple iterators are supported in read-write |
| 921 | // transactions, make sure this does not panic anymore. Then just |
| 922 | // close the iterator. |
| 923 | txn.NewIterator(DefaultIteratorOptions).Close() |
| 924 | }) |
| 925 | // The transaction should still panic since there is still one pending |
| 926 | // iterator that is open. |
nothing calls this directly
no test coverage detected
searching dependent graphs…