Skip to content

Conversation

@mafredri
Copy link
Member

@mafredri mafredri commented Oct 31, 2025

While doing a quick test/validation for #23, I used goleak to confirm that my suspicion wasn't warranted. Seemed like it would be a useful addition.

Adjusted the test structure slightly to fix the leak.

Before:

goleak: Errors on successful test run: found unexpected goroutines:
[Goroutine 65 in state sync.WaitGroup.Wait, with sync.runtime_SemacquireWaitGroup on top of the stack:
sync.runtime_SemacquireWaitGroup(0xc000302030?)
        /usr/local/go/src/runtime/sema.go:110 +0x25
sync.(*WaitGroup).Wait(0x0?)
        /usr/local/go/src/sync/waitgroup.go:118 +0x48
github.com/coder/quartz.(*Mock).matchCallLocked(0xc00030a000, 0xc0003240c0)
        /home/coder/quartz/mock.go:206 +0x328
github.com/coder/quartz.(*Mock).Now(0xc00030a000, {0x0?, 0xc00017dc00?, 0x5a4770?})
        /home/coder/quartz/mock.go:122 +0x10c
github.com/coder/quartz_test.Test_UnreleasedCalls.func1.1()
        /home/coder/quartz/mock_test.go:404 +0x1e
created by github.com/coder/quartz_test.Test_UnreleasedCalls.func1 in goroutine 16
        /home/coder/quartz/mock_test.go:403 +0xeb
]
exit status 1
FAIL    github.com/coder/quartz 2.460s

Now:

=== RUN   Test_UnreleasedCalls
=== PAUSE Test_UnreleasedCalls
=== CONT  Test_UnreleasedCalls
    mock.go:442: Mock Clock - Trap Now(..., [])
    mock.go:196: Mock Clock - Now([]) call, matched 1 traps
    mock_test.go:408: trap Closed() with 1 unreleased calls
    mock.go:484: Mock Clock - test cleanup; will no longer log clock events
--- PASS: Test_UnreleasedCalls (0.00s)
PASS
ok      github.com/coder/quartz 0.003s

@spikecurtis
Copy link
Collaborator

I thought about this, but right now Quartz has zero dependencies, which is appealing for a small test library. I don't think there is a way to tell Go that a library is only for test and doesn't need to be installed when someone imports Quartz.

Should we consider vendoring it?

@mafredri
Copy link
Member Author

That's a good point, I didn't consider it. Vendoring is definitely one option, although I think it'll still show up in go.mod if you go vendor it.

WDYT about a fairly trivial implementation like in a7c6e08 (#24)?

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