This is an automated email from the ASF dual-hosted git repository.

LinkinStars pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/answer.git

commit f5e25dcb8d7c793316161ce1a6925edb596e1d2e
Author: LinkinStars <[email protected]>
AuthorDate: Tue Jul 7 19:03:27 2026 +0800

    fix(notification): remove buffer size parameter from new question email 
worker for test
---
 .../notification/new_question_email_worker_test.go | 22 +++++------
 .../notification/new_question_notification_test.go | 45 +++++++++-------------
 2 files changed, 29 insertions(+), 38 deletions(-)

diff --git a/internal/service/notification/new_question_email_worker_test.go 
b/internal/service/notification/new_question_email_worker_test.go
index e7ea4880..739dfe50 100644
--- a/internal/service/notification/new_question_email_worker_test.go
+++ b/internal/service/notification/new_question_email_worker_test.go
@@ -346,7 +346,7 @@ func 
TestNewQuestionEmailWorkerBuildsFreshRawDataPerAttempt(t *testing.T) {
 }
 
 func TestNewQuestionEmailWorkerTryEnqueueCopiesTaskAndFailsFast(t *testing.T) {
-       worker := newUnstartedNewQuestionEmailWorkerForTest(1)
+       worker := newUnstartedNewQuestionEmailWorkerForTest()
        task := newQuestionEmailTask{
                UserIDs:       []string{"user-1"},
                QuestionTitle: "Question",
@@ -380,7 +380,7 @@ func 
TestNewQuestionEmailWorkerTryEnqueueCopiesTaskAndFailsFast(t *testing.T) {
                t.Fatalf("TryEnqueue() after Close() = true, want false")
        }
 
-       canceledWorker := newUnstartedNewQuestionEmailWorkerForTest(1)
+       canceledWorker := newUnstartedNewQuestionEmailWorkerForTest()
        canceledWorker.cancel()
        if canceledWorker.TryEnqueue(newQuestionEmailWorkerTask("question-5", 
"user-5")) {
                t.Fatalf("TryEnqueue() after cancel = true, want false")
@@ -393,8 +393,8 @@ func TestNewQuestionEmailWorkerTryEnqueueConcurrentClose(t 
*testing.T) {
                senders    = 32
        )
 
-       for iteration := 0; iteration < iterations; iteration++ {
-               worker := newUnstartedNewQuestionEmailWorkerForTest(1)
+       for iteration := range iterations {
+               worker := newUnstartedNewQuestionEmailWorkerForTest()
                if 
!worker.TryEnqueue(newQuestionEmailWorkerTask("already-queued", "queued-user")) 
{
                        t.Fatalf("iteration %d: pre-fill TryEnqueue() = false, 
want true", iteration)
                }
@@ -406,10 +406,8 @@ func TestNewQuestionEmailWorkerTryEnqueueConcurrentClose(t 
*testing.T) {
                var acceptedAfterCloseObserved atomic.Int64
                var wg sync.WaitGroup
 
-               for sender := 0; sender < senders; sender++ {
-                       wg.Add(1)
-                       go func(sender int) {
-                               defer wg.Done()
+               for range senders {
+                       wg.Go(func() {
                                defer func() {
                                        if recovered := recover(); recovered != 
nil {
                                                panicCh <- recovered
@@ -428,9 +426,9 @@ func TestNewQuestionEmailWorkerTryEnqueueConcurrentClose(t 
*testing.T) {
                                        }
                                        runtime.Gosched()
                                }
-                       }(sender)
+                       })
                }
-               for sender := 0; sender < senders; sender++ {
+               for range senders {
                        <-ready
                }
 
@@ -533,10 +531,10 @@ func newQuestionEmailWorkerTask(questionID string, 
userIDs ...string) newQuestio
        }
 }
 
-func newUnstartedNewQuestionEmailWorkerForTest(bufferSize int) 
*newQuestionEmailWorker {
+func newUnstartedNewQuestionEmailWorkerForTest() *newQuestionEmailWorker {
        ctx, cancel := context.WithCancel(context.Background())
        return &newQuestionEmailWorker{
-               tasks:        make(chan newQuestionEmailTask, bufferSize),
+               tasks:        make(chan newQuestionEmailTask, 1),
                interval:     func() time.Duration { return 0 },
                timerFactory: newRealNewQuestionEmailTimer,
                ctx:          ctx,
diff --git a/internal/service/notification/new_question_notification_test.go 
b/internal/service/notification/new_question_notification_test.go
index e7db3814..3bb6a3dd 100644
--- a/internal/service/notification/new_question_notification_test.go
+++ b/internal/service/notification/new_question_notification_test.go
@@ -181,7 +181,7 @@ func TestHandleNewQuestionNotificationEnqueuesEmailTask(t 
*testing.T) {
                },
                siteInfoService: siteInfoService,
        }
-       service.newQuestionEmailWorker = 
newUnstartedNewQuestionEmailWorkerForTest(1)
+       service.newQuestionEmailWorker = 
newUnstartedNewQuestionEmailWorkerForTest()
 
        err = service.handleNewQuestionNotification(context.Background(), 
&schema.ExternalNotificationMsg{
                NewQuestionTemplateRawData: &schema.NewQuestionTemplateRawData{
@@ -243,7 +243,7 @@ func 
TestHandleNewQuestionNotificationSkipsEnqueueWithoutEnabledEmailAttempts(t
                                "all-user": 
newQuestionNotificationTestUser("all-user"),
                        },
                },
-               newQuestionEmailWorker: 
newUnstartedNewQuestionEmailWorkerForTest(1),
+               newQuestionEmailWorker: 
newUnstartedNewQuestionEmailWorkerForTest(),
        }
 
        err = service.handleNewQuestionNotification(context.Background(), 
&schema.ExternalNotificationMsg{
@@ -271,7 +271,7 @@ func 
TestHandleNewQuestionNotificationReturnsWhenEmailWorkerQueueFull(t *testing
        }
        t.Cleanup(cleanup)
 
-       worker := newUnstartedNewQuestionEmailWorkerForTest(1)
+       worker := newUnstartedNewQuestionEmailWorkerForTest()
        if !worker.TryEnqueue(newQuestionEmailWorkerTask("already-queued", 
"queued-user")) {
                t.Fatalf("pre-fill TryEnqueue() = false, want true")
        }
@@ -332,7 +332,7 @@ func 
TestHandleNewQuestionNotificationSyncsPluginBeforeEmailEnqueue(t *testing.T
        releaseNotify := make(chan struct{})
        enableNewQuestionNotificationTestPlugin(t, notifyStarted, releaseNotify)
 
-       worker := newUnstartedNewQuestionEmailWorkerForTest(1)
+       worker := newUnstartedNewQuestionEmailWorkerForTest()
        service := &ExternalNotificationService{
                data: &basedata.Data{Cache: cache},
                userNotificationConfigRepo: 
&newQuestionNotificationTestUserNotificationConfigRepo{
@@ -428,13 +428,6 @@ func setNewQuestionNotificationEmailSendIntervalEnv(t 
*testing.T, value string,
        })
 }
 
-func newQuestionSubscriber(userID string, channels 
...*schema.NotificationChannelConfig) *NewQuestionSubscriber {
-       return &NewQuestionSubscriber{
-               UserID:   userID,
-               Channels: channels,
-       }
-}
-
 func newQuestionEmailChannel(enable bool) *schema.NotificationChannelConfig {
        return &schema.NotificationChannelConfig{
                Key:    constant.EmailChannel,
@@ -442,13 +435,6 @@ func newQuestionEmailChannel(enable bool) 
*schema.NotificationChannelConfig {
        }
 }
 
-func newQuestionNonEmailChannel(enable bool) *schema.NotificationChannelConfig 
{
-       return &schema.NotificationChannelConfig{
-               Key:    constant.NotificationChannelKey("inbox"),
-               Enable: enable,
-       }
-}
-
 func newQuestionNotificationConfig(
        userID string, source constant.NotificationSource, emailEnabled bool) 
*entity.UserNotificationConfig {
        channels := schema.NotificationChannels{
@@ -702,14 +688,6 @@ func (r *newQuestionNotificationTestEmailRepo) 
VerifyCode(context.Context, strin
        return "", nil
 }
 
-func (r *newQuestionNotificationTestEmailRepo) userIDs() []string {
-       userIDs := make([]string, 0, len(r.codesByUserID))
-       for userID := range r.codesByUserID {
-               userIDs = append(userIDs, userID)
-       }
-       return userIDs
-}
-
 var (
        newQuestionNotificationTestPluginOnce sync.Once
        newQuestionNotificationTestPluginInst = 
&newQuestionNotificationTestPlugin{}
@@ -820,3 +798,18 @@ func (newQuestionNotificationTestUserExternalLoginRepo) 
GetCacheUserExternalLogi
        context.Context, string) (*schema.ExternalLoginUserInfoCache, error) {
        return nil, nil
 }
+
+func (newQuestionNotificationTestUserExternalLoginRepo) SetCacheOAuthState(
+       context.Context, string, *schema.ExternalLoginOAuthState, 
time.Duration) error {
+       return nil
+}
+
+func (newQuestionNotificationTestUserExternalLoginRepo) GetCacheOAuthState(
+       context.Context, string) (*schema.ExternalLoginOAuthState, error) {
+       return nil, nil
+}
+
+func (newQuestionNotificationTestUserExternalLoginRepo) DeleteCacheOAuthState(
+       context.Context, string) error {
+       return nil
+}

Reply via email to