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

invalid timer's Reset result value #3

Closed
LopatkinEvgeniy opened this issue Oct 9, 2018 · 3 comments
Closed

invalid timer's Reset result value #3

LopatkinEvgeniy opened this issue Oct 9, 2018 · 3 comments

Comments

@LopatkinEvgeniy
Copy link

Stress test to reproduce:

func TestFakeTimerResetStress(t *testing.T) {
    c := NewManual()
    d := time.Hour
    timer := c.NewTimer(d, timerID)

    for i := 0; i < 100000; i++ {
        go func() {
            c.Advance(d)
            c.Trigger(timerID)
        }()

        actualTime := <-timer.Channel()
        expectedTime := c.Now()
        if expectedTime != actualTime {
            t.Fatalf("Unexpected time received from the channel, expected=%s, actual=%s", expectedTime, actualTime)
        }

        wasActive := timer.Reset(d)
        if wasActive {
            t.Fatal("Unexpected reset result value")
        }
    }
}

Result:

go test ./ --run=TestFakeTimerResetStress
--- FAIL: TestFakeTimerResetStress (0.00s)
    manual_test.go:36: Unexpected reset result value
FAIL
FAIL    github.com/thejerf/abtime    0.001s
@LopatkinEvgeniy
Copy link
Author

LopatkinEvgeniy commented Oct 9, 2018

Reset must return false when timer expired.

thejerf pushed a commit that referenced this issue Oct 12, 2018
This closes Issue #3.

It also fixes a race condition in setting the .stopped value for the timer.
@thejerf
Copy link
Owner

thejerf commented Oct 12, 2018

Thank you for your report. I also found a race condition; the tick is sent down the channel and then the .stopped flag is updated. It needs to be the other way around. I've released a v1.0.1 to address this.

@thejerf thejerf closed this as completed Oct 12, 2018
@thejerf
Copy link
Owner

thejerf commented Oct 12, 2018

Also, thanks for letting me know somebody else uses this. :) I still use it on almost every project, so I know it's useful to at least some degree.

I've examined using the ability to export types to make a true drop-in to the time library with the exact same API, but I can't work out any way to avoid having to label the various different uses of the time functions one way or another.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants