Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TestRingLossy fails with drain error #60

Closed
jarifibrahim opened this issue Sep 24, 2019 · 4 comments
Closed

TestRingLossy fails with drain error #60

jarifibrahim opened this issue Sep 24, 2019 · 4 comments
Assignees
Labels
kind/bug Something is broken.
Milestone

Comments

@jarifibrahim
Copy link
Contributor

jarifibrahim commented Sep 24, 2019

TestRingLossy fails on master with drain error

Run

while go clean -testcache && go test -v -race -run='TestRingLossy' -timeout=1m; do :; done    

to reproduce the failure

=== RUN   TestRingLossy
--- FAIL: TestRingLossy (0.01s)
    ring_test.go:57: drain error
FAIL
exit status 1
FAIL	github.com/dgraph-io/ristretto	0.012s

ristretto/ring_test.go

Lines 41 to 59 in ae326c3

func TestRingLossy(t *testing.T) {
drainCount := 0
buffer := newRingBuffer(ringLossy, &ringConfig{
Consumer: &TestConsumer{
push: func(items []uint64) {
drainCount++
},
},
Capacity: 4,
})
buffer.Push(1)
buffer.Push(2)
buffer.Push(3)
buffer.Push(4)
time.Sleep(5 * time.Millisecond)
if drainCount == 0 {
t.Fatal("drain error")
}
}

@jarifibrahim jarifibrahim added the kind/bug Something is broken. label Sep 24, 2019
@jarifibrahim jarifibrahim self-assigned this Sep 24, 2019
@jarifibrahim
Copy link
Contributor Author

ristretto/ring.go

Lines 127 to 132 in ae326c3

func pushLossy(b *ringBuffer, item uint64) {
// reuse or create a new stripe
stripe := b.pool.Get().(*ringStripe)
stripe.Push(item)
b.pool.Put(stripe)
}
uses sync.Pool(..) and sync.Pool is not guaranteed to return the objects that were inserted into it.
When the test is run with -race flag, there are multiple ring strips created and hence none of them reach capacity.

@karlmcguire
Copy link
Contributor

I see. We need another way to make sure ringLossy is draining properly even with the -race flag. The behavior we're seeing now is the correct behavior, it's just hard to test.

@karlmcguire
Copy link
Contributor

Here's what I'm thinking, rather than an exact, single threaded test:

func TestRingLossy(t *testing.T) {
	drainCount := 0
	buffer := newRingBuffer(ringLossy, &ringConfig{
		Consumer: &TestConsumer{
			push: func(items []uint64) {
				drainCount++
			},
		},
		Capacity: 4,
	})
	for i := 0; i < 100; i++ {
		buffer.Push(uint64(i))
	}
	// ideally we'd be able to check for a certain "drop percentage" here, but
	// that may vary per platform and testing configuration. for example: if
	// drainCount == 20 then we have 100% accuracy, but it's most likely around
	// 13-20 due to dropping and unfilled rings.
	if drainCount == 0 {
		t.Fatal("drain error")
	}
}

@jarifibrahim
Copy link
Contributor Author

@karlmcguire I thought of doing something along similar lines. Do you mind sending a PR? I ran your snippet and I didn't see any failures after running the test for ~10m.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something is broken.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants