github.com/voedger/voedger@v0.0.0-20240520144910-273e84102129/pkg/sys/it/race_n10n_test.go (about) 1 /* 2 * Copyright (c) 2021-present unTill Pro, Ltd. 3 */ 4 5 package sys_it 6 7 import ( 8 "sync" 9 "testing" 10 11 "github.com/stretchr/testify/require" 12 "github.com/voedger/voedger/pkg/appdef" 13 "github.com/voedger/voedger/pkg/in10n" 14 "github.com/voedger/voedger/pkg/istructs" 15 coreutils "github.com/voedger/voedger/pkg/utils" 16 "github.com/voedger/voedger/pkg/utils/federation" 17 it "github.com/voedger/voedger/pkg/vit" 18 ) 19 20 // Test_Race_n10nCHS: Create channel and wait for subscribe 21 func Test_Race_n10nCHS(t *testing.T) { 22 if testing.Short() { 23 t.Skip() 24 } 25 if coreutils.IsCassandraStorage() { 26 return 27 } 28 vit := it.NewVIT(t, &it.SharedConfig_App1) 29 defer vit.TearDown() 30 31 wg := &sync.WaitGroup{} 32 cnt := 100 33 unsubscribes := make(chan func(), cnt) 34 offsetsChans := make(chan federation.OffsetsChan, cnt) 35 for wsid := istructs.WSID(0); wsid < istructs.WSID(cnt); wsid++ { 36 wg.Add(1) 37 go func(wsid istructs.WSID) { 38 defer wg.Done() 39 offsetsChan, unsubscribe, err := vit.N10NSubscribe(in10n.ProjectionKey{ 40 App: istructs.NewAppQName("untill", "Application"), 41 Projection: appdef.NewQName("paa", "price"), 42 WS: wsid, 43 }) 44 require.NoError(t, err) 45 unsubscribes <- unsubscribe 46 offsetsChans <- offsetsChan 47 }(wsid) 48 } 49 wg.Wait() 50 close(unsubscribes) 51 close(offsetsChans) 52 for unsubscribe := range unsubscribes { 53 unsubscribe() 54 } 55 for offsetsChan := range offsetsChans { 56 for range offsetsChan { 57 } 58 } 59 } 60 61 // Test_Race_n10nCHSU: Create channel, read event, send update 62 func Test_Race_n10nCHSU(t *testing.T) { 63 if testing.Short() { 64 t.Skip() 65 } 66 if coreutils.IsCassandraStorage() { 67 return 68 } 69 vit := it.NewVIT(t, &it.SharedConfig_App1) 70 defer vit.TearDown() 71 72 wg := sync.WaitGroup{} 73 cnt := 10 74 unsubscribes := make(chan func(), cnt) 75 offsetsChans := make(chan federation.OffsetsChan, cnt) 76 for wsid := istructs.WSID(0); wsid < istructs.WSID(cnt); wsid++ { 77 wg.Add(1) 78 go func(wsid istructs.WSID) { 79 defer wg.Done() 80 81 // create chan and subscribe 82 projectionKey := in10n.ProjectionKey{ 83 App: istructs.AppQName_test1_app1, 84 Projection: appdef.NewQName("paa", "price"), 85 WS: wsid, 86 } 87 offsetsChan, unsubscribe, err := vit.N10NSubscribe(projectionKey) 88 require.NoError(t, err) 89 unsubscribes <- unsubscribe 90 offsetsChans <- offsetsChan 91 92 // upate 93 require.NoError(t, vit.N10NUpdate(projectionKey, 13)) 94 }(wsid) 95 } 96 wg.Wait() 97 close(unsubscribes) 98 close(offsetsChans) 99 wg = sync.WaitGroup{} 100 for offsetsChan := range offsetsChans { 101 wg.Add(1) 102 go func(offsetsChan federation.OffsetsChan) { 103 defer wg.Done() 104 for offset := range offsetsChan { 105 require.Equal(t, istructs.Offset(13), offset) 106 } 107 }(offsetsChan) 108 } 109 for unsubscribe := range unsubscribes { 110 unsubscribe() 111 } 112 wg.Wait() 113 }