Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

test(coderd/notifications): fix data race in tests and smpttest#15304

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
mafredri merged 3 commits intomainfrommafredri/fix-data-race-smtp-notif
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletioncoderd/notifications/dispatch/smtptest/server.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,7 @@ import (
_ "embed"
"io"
"net"
"slices"
"sync"
"time"

Expand DownExpand Up@@ -53,11 +54,22 @@ func (b *Backend) NewSession(c *smtp.Conn) (smtp.Session, error) {
return &Session{conn: c, backend: b}, nil
}

// LastMessage returns a copy of the last message received by the
// backend.
func (b *Backend) LastMessage() *Message {
return b.lastMsg
b.mu.Lock()
defer b.mu.Unlock()
if b.lastMsg == nil {
return nil
}
clone := *b.lastMsg
clone.To = slices.Clone(b.lastMsg.To)
return &clone
}

func (b *Backend) Reset() {
b.mu.Lock()
defer b.mu.Unlock()
b.lastMsg = nil
}

Expand All@@ -84,6 +96,9 @@ func (s *Session) Auth(mech string) (sasl.Server, error) {
switch mech {
case sasl.Plain:
return sasl.NewPlainServer(func(identity, username, password string) error {
s.backend.mu.Lock()
defer s.backend.mu.Unlock()

s.backend.lastMsg.Identity = identity
s.backend.lastMsg.Username = username
s.backend.lastMsg.Password = password
Expand All@@ -102,6 +117,9 @@ func (s *Session) Auth(mech string) (sasl.Server, error) {
}), nil
case sasl.Login:
return sasl.NewLoginServer(func(username, password string) error {
s.backend.mu.Lock()
defer s.backend.mu.Unlock()

s.backend.lastMsg.Username = username
s.backend.lastMsg.Password = password

Expand Down
15 changes: 7 additions & 8 deletionscoderd/notifications/notifications_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1253,12 +1253,12 @@ func TestNotificationTemplates_Golden(t *testing.T) {
// Spin up the mock webhook server
var body []byte
var readErr error
varwebhookReceivedbool
webhookReceived:= make(chan struct{})
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)

body, readErr = io.ReadAll(r.Body)
webhookReceived = true
close(webhookReceived)
}))
t.Cleanup(server.Close)

Expand DownExpand Up@@ -1302,12 +1302,11 @@ func TestNotificationTemplates_Golden(t *testing.T) {
)
require.NoError(t, err)

require.Eventually(t, func() bool {
return webhookReceived
}, testutil.WaitShort, testutil.IntervalFast)

require.NoError(t, err)

select {
case <-time.After(testutil.WaitShort):
require.Fail(t, "timed out waiting for webhook to be received")
case <-webhookReceived:
}
// Handle the body that was read in the http server here.
// We need to do it here because we can't call require.* in a separate goroutine, such as the http server handler
require.NoError(t, readErr)
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp