GithubHelp home page GithubHelp logo

Comments (4)

karlmcguire avatar karlmcguire commented on April 27, 2024 1

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")
	}
}

from ristretto.

jarifibrahim avatar jarifibrahim commented on April 27, 2024 1

@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.

from ristretto.

jarifibrahim avatar jarifibrahim commented on April 27, 2024

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.

from ristretto.

karlmcguire avatar karlmcguire commented on April 27, 2024

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.

from ristretto.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.