Skip to content

fix a bug where AdvanceNext unlocks twice #10

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

Merged
merged 1 commit into from
Nov 20, 2024
Merged

fix a bug where AdvanceNext unlocks twice #10

merged 1 commit into from
Nov 20, 2024

Conversation

edwingeng
Copy link
Contributor

How to reproduce:

func TestQuartz_AdvanceNext(t *testing.T) {
    clock := quartz.NewMock(t)
    clock.AdvanceNext()
    time.Sleep(time.Second)
}

Output:

fatal error: sync: unlock of unlocked mutex

goroutine 19 [running]:
sync.fatal({0x86845ba?, 0x86dd020?})
    runtime/panic.go:1031 +0x18
sync.(*Mutex).unlockSlow(0xc0000f2010, 0xffffffff)
    sync/mutex.go:231 +0x35
sync.(*Mutex).Unlock(...)
    sync/mutex.go:225
github.com/coder/quartz.(*Mock).advanceLocked(0xc0000f2000, {{0x86f6058?, 0xc0000a6820?}, 0xc00008e310?})
    github.com/coder/quartz/mock.go:299 +0x1a7
created by github.com/coder/quartz.(*Mock).AdvanceNext in goroutine 18
    github.com/coder/quartz/mock.go:355 +0x28b

goroutine 1 [chan receive]:
testing.(*T).Run(0xc0000a6680, {0x8681fa8?, 0xfb73180009ab50?}, 0x86f2f68)
    testing/testing.go:1751 +0x3ab
testing.runTests.func1(0xc0000a6680)
    testing/testing.go:2168 +0x37
testing.tRunner(0xc0000a6680, 0xc00009ac70)
    testing/testing.go:1690 +0xf4
testing.runTests(0xc00009e180, {0x87d5d60, 0x9, 0x9}, {0x85bd7d0?, 0x85bd43a?, 0x87da620?})
    testing/testing.go:2166 +0x43d
testing.(*M).Run(0xc0000ac0a0)
    testing/testing.go:2034 +0x64a
main.main()
    _testmain.go:63 +0x9b

goroutine 18 [sleep]:
time.Sleep(0x3b9aca00)
    runtime/time.go:300 +0xf2
github.com/coder/quartz_test.TestQuartz_AdvanceNext(0xc0000a6820?)
    github.com/coder/quartz/mock_test.go:326 +0x2f
testing.tRunner(0xc0000a6820, 0x86f2f68)
    testing/testing.go:1690 +0xf4
created by testing.(*T).Run in goroutine 1
    testing/testing.go:1743 +0x390
exit status 2

Cause:

https://github.com/coder/quartz/blob/7f10f7fd6925130f6548710df54992e832cfce2d/mock.go#L348

@edwingeng edwingeng closed this Nov 19, 2024
@edwingeng edwingeng reopened this Nov 19, 2024
@edwingeng edwingeng changed the title fix a bug where AdvanceNext unlock twice fix a bug where AdvanceNext unlocks twice Nov 19, 2024
@spikecurtis spikecurtis self-requested a review November 20, 2024 06:41
Copy link
Collaborator

@spikecurtis spikecurtis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Nice catch.

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

Successfully merging this pull request may close these issues.

2 participants