go-pkgz / auth

Authenticator via oauth2, direct, email and telegram
https://go-pkgz.umputun.dev/auth/
MIT License
1.07k stars 84 forks source link

Fix TestTelegramConfirmedRequest #215

Closed cyb3r4nt closed 2 months ago

cyb3r4nt commented 2 months ago

There were two different race conditions between logic in TestTelegramConfirmedRequest and TelegramAPIMock.GetUpdatesFunc and TelegramAPIMock.SendFunc:

Some of these failures were observed here: https://github.com/go-pkgz/auth/actions/runs/10632296696/job/29474964583?pr=214#step:6:778

=== RUN   TestTelegramUnconfirmedRequest
--- PASS: TestTelegramUnconfirmedRequest (0.12s)
=== RUN   TestTelegramConfirmedRequest
--- PASS: TestTelegramConfirmedRequest (0.03s)
=== RUN   TestTelegramLogout
panic: Fail in goroutine after TestTelegramConfirmedRequest has completed

goroutine 394 [running]:
testing.(*common).Fail(0xc000083ba0)
    /opt/hostedtoolcache/go/1.21.13/x64/src/testing/testing.go:952 +0x1b4
testing.(*common).Errorf(0xc000083ba0, {0xf4a4ad, 0x3}, {0xc000419ca0, 0x1, 0x1})
    /opt/hostedtoolcache/go/1.21.13/x64/src/testing/testing.go:1069 +0xaf
github.com/stretchr/testify/assert.Fail({0x11d5da0, 0xc000083ba0}, {0xc0000c6070, 0x6d}, {0x0, 0x0, 0x0})
    /home/runner/go/pkg/mod/github.com/stretchr/testify@v1.9.0/assert/assertions.go:363 +0x436
github.com/stretchr/testify/assert.Equal({0x11d5da0, 0xc000083ba0}, {0xe6df40?, 0x11d3460}, {0xe6df40?, 0xc000419b60?}, {0x0, 0x0, 0x0})
    /home/runner/go/pkg/mod/github.com/stretchr/testify@v1.9.0/assert/assertions.go:466 +0x3d8
github.com/go-pkgz/auth/v2/provider.TestTelegramConfirmedRequest.func3({0x11dbb50, 0xc000458eb0}, 0x1?, {0xf4aef0, 0x5})
    /home/runner/work/auth/auth/v2/provider/telegram_test.go:126 +0x116
github.com/go-pkgz/auth/v2/provider.(*TelegramAPIMock).Send(0xc0002c08c0, {0x11dbb50, 0xc000458eb0}, 0x12aa0131, {0xf4aef0, 0x5})
    /home/runner/work/auth/auth/v2/provider/telegram_moq_test.go:204 +0x279
github.com/go-pkgz/auth/v2/provider.(*TelegramHandler).processUpdates(0xc000272f20, {0x11dbb50, 0xc000458eb0}, 0xc0001b3740)
    /home/runner/work/auth/auth/v2/provider/telegram.go:173 +0xb7d
github.com/go-pkgz/auth/v2/provider.(*TelegramHandler).Run(0xc000272f20, {0x11dbb50, 0xc000458eb0})
    /home/runner/work/auth/auth/v2/provider/telegram.go:94 +0x5d2
github.com/go-pkgz/auth/v2/provider.setupHandler.func2()
    /home/runner/work/auth/auth/v2/provider/telegram_test.go:398 +0x66
created by github.com/go-pkgz/auth/v2/provider.setupHandler in goroutine 393
    /home/runner/work/auth/auth/v2/provider/telegram_test.go:397 +0x5eb
FAIL    github.com/go-pkgz/auth/v2/provider 5.645s
=== RUN   TestEmailSend
    email_test.go:15: 
--- SKIP: TestEmailSend (0.00s)
=== RUN   TestEmail_New
--- PASS: TestEmail_New (0.00s)
=== RUN   TestEmail_SendFailed