From 5b58a78e64b9424eee87dc53746cbfbf858d3fb7 Mon Sep 17 00:00:00 2001 From: Gani Georgiev Date: Mon, 1 Jul 2024 20:53:48 +0300 Subject: [PATCH] [#5157] added `tests.TestMailer` mutex --- CHANGELOG.md | 5 +++++ tests/mailer.go | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bc7e6765..cb2dd29a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## v0.22.15-WIP + +- Added `tests.TestMailer` mutex to minimize the data race warnings during tests ([#5157](https://github.com/pocketbase/pocketbase/issues/5157)). + + ## v0.22.14 - Added OAuth2 POST redirect support (in case of `response_mode=form_post`) to allow specifying scopes for the Apple OAuth2 integration. diff --git a/tests/mailer.go b/tests/mailer.go index 82d97c1f..9672ad8b 100644 --- a/tests/mailer.go +++ b/tests/mailer.go @@ -1,6 +1,8 @@ package tests import ( + "sync" + "github.com/pocketbase/pocketbase/tools/mailer" ) @@ -8,6 +10,8 @@ var _ mailer.Mailer = (*TestMailer)(nil) // TestMailer is a mock `mailer.Mailer` implementation. type TestMailer struct { + mux sync.Mutex + TotalSend int LastMessage mailer.Message @@ -17,6 +21,9 @@ type TestMailer struct { // Reset clears any previously test collected data. func (tm *TestMailer) Reset() { + tm.mux.Lock() + defer tm.mux.Unlock() + tm.TotalSend = 0 tm.LastMessage = mailer.Message{} tm.SentMessages = nil @@ -24,6 +31,9 @@ func (tm *TestMailer) Reset() { // Send implements `mailer.Mailer` interface. func (tm *TestMailer) Send(m *mailer.Message) error { + tm.mux.Lock() + defer tm.mux.Unlock() + tm.TotalSend++ tm.LastMessage = *m tm.SentMessages = append(tm.SentMessages, tm.LastMessage)