返回 DeepSeek-Reasonix
tab_concurrent_activation_test.go
根目录 / desktop / tab_concurrent_activation_test.go
1 package main
2
3 import (
4 "context"
5 "errors"
6 "sync"
7 "testing"
8 )
9
10 func TestConcurrentActivateTopicSerializesSingleSurfacePruning(t *testing.T) {
11 isolateDesktopUserDirs(t)
12 app := NewApp()
13 t.Cleanup(func() { app.shutdown(context.Background()) })
14
15 topics := []string{
16 "topic-a",
17 "topic-b",
18 "topic-c",
19 "topic-d",
20 "topic-e",
21 "topic-f",
22 "topic-g",
23 "topic-h",
24 }
25 start := make(chan struct{})
26 errs := make(chan error, len(topics))
27 var wg sync.WaitGroup
28 for _, topicID := range topics {
29 wg.Add(1)
30 go func(topicID string) {
31 defer wg.Done()
32 <-start
33 _, err := app.ActivateTopic("global", "", topicID, "")
34 errs <- err
35 }(topicID)
36 }
37 close(start)
38 wg.Wait()
39 close(errs)
40
41 succeeded := 0
42 for err := range errs {
43 if err == nil {
44 succeeded++
45 } else if !errors.Is(err, errSessionNavigationSuperseded) {
46 t.Fatalf("ActivateTopic returned error under concurrent navigation: %v", err)
47 }
48 }
49 if succeeded == 0 {
50 t.Fatal("every request was superseded; the latest navigation must succeed")
51 }
52 tabs := app.ListTabs()
53 if len(tabs) != 1 {
54 t.Fatalf("ListTabs returned %d tabs after single-surface navigation, want 1: %+v", len(tabs), tabs)
55 }
56 if !tabs[0].Active {
57 t.Fatalf("remaining tab is not active: %+v", tabs[0])
58 }
59 }
60
60 lines GO