Coder Social home page Coder Social logo

TestDisplayMetrics flaky about go-metrics HOT 2 OPEN

hashicorp avatar hashicorp commented on August 17, 2024 2
TestDisplayMetrics flaky

from go-metrics.

Comments (2)

dnephin avatar dnephin commented on August 17, 2024

Thank you for the bug report!

Looking at this test, I believe what's happening is that we use https://pkg.go.dev/time#Time.Truncate to split time into intervals. If some of the test data is added before the interval boundary, and some of it is added after the boundary, we'll end up with two intervals for this test, and the test expects only one.

One way to fix this might be to increase the interval in that test slightly from 10ms to 20ms (to give us more buffer). Then when we get the first interval, wait for it to finish (the done chan was added recently in #125), and add all the metrics immediately after it finishes:

interval := 20 * time.Millisecond
inm := NewInmemSink(interval, 50*time.Millisecond)
<- inm.getInterval().done
// add all the sample metrics

data := inm.Data()
// now we expect 2 intervals in data instead of one.
...

As long as all the metrics can be added in 20ms and we call DisplayMetrics before the next interval, the test should not longer flake.

Edit: Ah but done is only closed when something calls getInterval, so we'll also need a goroutine to call that constantly to get the signal. Maybe using a time.After to wait on the interval boundary would be easier than using the done channel.

There are probably other options for fixing it as well.

from go-metrics.

elboulangero avatar elboulangero commented on August 17, 2024

Edit: Ah but done is only closed when something calls getInterval, so we'll also need a goroutine to call that constantly to get the signal. Maybe using a time.After to wait on the interval boundary would be easier than using the done channel.

I can confirm that. I tried the change you suggested above, and the test gets stuck, and finally times out after 10 minutes.

Logs for reference:

=== RUN   TestDisplayMetrics
panic: test timed out after 10m0s

goroutine 7 [running]:
testing.(*M).startAlarm.func1()
	/usr/lib/go-1.16/src/testing/testing.go:1700 +0xe5
created by time.goFunc
	/usr/lib/go-1.16/src/time/sleep.go:180 +0x45

goroutine 1 [chan receive]:
testing.(*T).Run(0xc000001b00, 0x66fce6, 0x12, 0x6809f8, 0x48f0a6)
	/usr/lib/go-1.16/src/testing/testing.go:1239 +0x2da
testing.runTests.func1(0xc000001980)
	/usr/lib/go-1.16/src/testing/testing.go:1511 +0x78
testing.tRunner(0xc000001980, 0xc00010dde0)
	/usr/lib/go-1.16/src/testing/testing.go:1193 +0xef
testing.runTests(0xc00000e0d8, 0x7f0040, 0x2a, 0x2a, 0xc047e14ce3db0d3d, 0x8bb2e16fb0, 0x7f54c0, 0x66e426)
	/usr/lib/go-1.16/src/testing/testing.go:1509 +0x2fe
testing.(*M).Run(0xc000154000, 0x0)
	/usr/lib/go-1.16/src/testing/testing.go:1417 +0x1eb
main.main()
	_testmain.go:127 +0x138

goroutine 6 [chan receive]:
github.com/armon/go-metrics.TestDisplayMetrics(0xc000001b00)
	/<<PKGBUILDDIR>>/obj-x86_64-linux-gnu/src/github.com/armon/go-metrics/inmem_endpoint_test.go:18 +0xe5
testing.tRunner(0xc000001b00, 0x6809f8)
	/usr/lib/go-1.16/src/testing/testing.go:1193 +0xef
created by testing.(*T).Run
	/usr/lib/go-1.16/src/testing/testing.go:1238 +0x2b3

from go-metrics.

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.