github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/chat/globals/context_test.go (about) 1 package globals 2 3 import ( 4 "context" 5 "testing" 6 7 "github.com/keybase/client/go/chat/types" 8 "github.com/keybase/client/go/externalstest" 9 "github.com/keybase/client/go/protocol/chat1" 10 "github.com/keybase/client/go/protocol/keybase1" 11 "github.com/stretchr/testify/require" 12 "golang.org/x/sync/errgroup" 13 ) 14 15 func TestConcurrentContext(t *testing.T) { 16 tc := externalstest.SetupTest(t, "Context", 1) 17 defer tc.Cleanup() 18 g := NewContext(tc.G, &ChatContext{ 19 CtxFactory: types.DummyCtxFactory{}, 20 }) 21 ctx := ChatCtx(context.TODO(), g, keybase1.TLFIdentifyBehavior_CHAT_CLI, nil, nil) 22 convID := chat1.ConversationID([]byte("deadbeef")) 23 eg := errgroup.Group{} 24 for i := 0; i < 5; i++ { 25 eg.Go(func() error { 26 for j := 0; j < 50; j++ { 27 CtxAddMessageCacheSkips(ctx, convID, []chat1.MessageUnboxed{ 28 // drop two empty msgs in 29 {}, 30 {}, 31 }) 32 } 33 return nil 34 }) 35 } 36 err := eg.Wait() 37 require.NoError(t, err) 38 res := CtxMessageCacheSkips(ctx) 39 require.Len(t, res, 1) 40 require.Len(t, res[0].Msgs, 5*50*2) 41 }