Giter Club home page Giter Club logo

Comments (3)

tsingson avatar tsingson commented on May 23, 2024

testing in linux

/home/go/src/github.com/tsingson/timingwheel #  go version
go version go1.12.9 linux/amd64
/home/go/src/github.com/tsingson/timingwheel #  
/home/go/src/github.com/tsingson/timingwheel #  go test -race  -count=1 .
FAIL
FAIL	github.com/RussellLuo/timingwheel	3.606s
/home/go/src/github.com/tsingson/timingwheel #  go test -race -v  -count=1 .
=== RUN   TestTimingWheel_AfterFunc
=== RUN   TestTimingWheel_AfterFunc/#00
=== RUN   TestTimingWheel_AfterFunc/#01
=== RUN   TestTimingWheel_AfterFunc/#02
=== RUN   TestTimingWheel_AfterFunc/#03
=== RUN   TestTimingWheel_AfterFunc/#04
=== RUN   TestTimingWheel_AfterFunc/#05
=== RUN   TestTimingWheel_AfterFunc/#06
--- FAIL: TestTimingWheel_AfterFunc (1.73s)
    --- FAIL: TestTimingWheel_AfterFunc/#00 (0.01s)
        timingwheel_test.go:38: NewTimer(1ms) want [2019-08-19 02:30:04.941 +0000 UTC, 2019-08-19 02:30:04.946 +0000 UTC], got 2019-08-19 02:30:04.95 +0000 UTC
        testing.go:809: race detected during execution of test
    --- PASS: TestTimingWheel_AfterFunc/#01 (0.01s)
    --- PASS: TestTimingWheel_AfterFunc/#02 (0.01s)
    --- PASS: TestTimingWheel_AfterFunc/#03 (0.05s)
    --- PASS: TestTimingWheel_AfterFunc/#04 (0.10s)
    --- PASS: TestTimingWheel_AfterFunc/#05 (0.50s)
    --- PASS: TestTimingWheel_AfterFunc/#06 (1.04s)
    testing.go:809: race detected during execution of test
=== RUN   Example_startTimer
--- PASS: Example_startTimer (1.00s)
=== RUN   Example_stopTimer
--- PASS: Example_stopTimer (0.90s)
FAIL
FAIL	github.com/RussellLuo/timingwheel	3.652s
/home/go/src/github.com/tsingson/timingwheel #  

from timingwheel.

tsingson avatar tsingson commented on May 23, 2024

change testing code to

package timingwheel_test

import (
	"testing"
	"time"

	"github.com/RussellLuo/timingwheel"
)

func TestTimingWheel_AfterFunc(t *testing.T) {
	tw := timingwheel.NewTimingWheel(time.Millisecond, 20)
	tw.Start()
	defer tw.Stop()

	durations := []time.Duration{
		//1 * time.Millisecond,
		5 * time.Millisecond,
		10 * time.Millisecond,
		50 * time.Millisecond,
		100 * time.Millisecond,
		500 * time.Millisecond,
		1 * time.Second,
	}
	for _, d := range durations {
		t.Run("", func(t *testing.T) {
			exitC := make(chan time.Time)

			start := time.Now()
			tw.AfterFunc(d, func() {
				exitC <- time.Now()
			})

			got := (<-exitC).Truncate(time.Millisecond)
			min := start.Add(d).Truncate(time.Millisecond)

			err := 5 * time.Millisecond
			if got.Before(min) || got.After(min.Add(err)) {
				t.Errorf("NewTimer(%s) want [%s, %s], got %s", d, min, min.Add(err), got)
			}
		})
	}
}

result is OK:

/home/go/src/github.com/tsingson/timingwheel #  go test -race -v  -count=1 .
=== RUN   TestTimingWheel_AfterFunc
=== RUN   TestTimingWheel_AfterFunc/#00
=== RUN   TestTimingWheel_AfterFunc/#01
=== RUN   TestTimingWheel_AfterFunc/#02
=== RUN   TestTimingWheel_AfterFunc/#03
=== RUN   TestTimingWheel_AfterFunc/#04
=== RUN   TestTimingWheel_AfterFunc/#05
--- PASS: TestTimingWheel_AfterFunc (1.68s)
    --- PASS: TestTimingWheel_AfterFunc/#00 (0.01s)
    --- PASS: TestTimingWheel_AfterFunc/#01 (0.01s)
    --- PASS: TestTimingWheel_AfterFunc/#02 (0.05s)
    --- PASS: TestTimingWheel_AfterFunc/#03 (0.10s)
    --- PASS: TestTimingWheel_AfterFunc/#04 (0.50s)
    --- PASS: TestTimingWheel_AfterFunc/#05 (1.00s)
=== RUN   Example_startTimer
--- PASS: Example_startTimer (1.00s)
=== RUN   Example_stopTimer
--- PASS: Example_stopTimer (0.90s)
FAIL
FAIL	github.com/RussellLuo/timingwheel	3.605s
/home/go/src/github.com/tsingson/timingwheel #  

that meaning , delay must more than 1ms ????

try

@ -13,7 +13,7 @@ func TestTimingWheel_AfterFunc(t *testing.T) {
	defer tw.Stop()

	durations := []time.Duration{
//		1 * time.Millisecond,
		2 * time.Millisecond,
		5 * time.Millisecond,
		10 * time.Millisecond,
		50 * time.Millisecond,

it's PASS all testing and no data race.

from timingwheel.

RussellLuo avatar RussellLuo commented on May 23, 2024

@tsingson Sorry for the delayed reply.

From your reporting, obviously, this is an issue of data race. I'll fix it soon.

from timingwheel.

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.