MCPcopy Index your code
hub / github.com/wavetermdev/waveterm / TestConcurrentAppend

Function TestConcurrentAppend

pkg/filestore/blockstore_test.go:612–650  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

610}
611
612func TestConcurrentAppend(t *testing.T) {
613 initDb(t)
614 defer cleanupDb(t)
615 ctx, cancelFn := context.WithTimeout(context.Background(), 5*time.Second)
616 defer cancelFn()
617 zoneId := uuid.NewString()
618 fileName := "t1"
619 err := WFS.MakeFile(ctx, zoneId, fileName, nil, wshrpc.FileOpts{})
620 if err != nil {
621 t.Fatalf("error creating file: %v", err)
622 }
623 var wg sync.WaitGroup
624 for i := 0; i < 16; i++ {
625 wg.Add(1)
626 go func(n int) {
627 defer wg.Done()
628 const hexChars = "0123456789abcdef"
629 ch := hexChars[n]
630 for j := 0; j < 100; j++ {
631 err := WFS.AppendData(ctx, zoneId, fileName, []byte{ch})
632 if err != nil {
633 t.Errorf("error appending data (%d): %v", n, err)
634 }
635 if j == 50 {
636 // ignore error here (concurrent flushing)
637 WFS.FlushCache(ctx)
638 }
639 }
640 }(i)
641 }
642 wg.Wait()
643 checkFileSize(t, ctx, zoneId, fileName, 1600)
644 checkFileByteCount(t, ctx, zoneId, fileName, 'a', 100)
645 checkFileByteCount(t, ctx, zoneId, fileName, 'e', 100)
646 WFS.FlushCache(ctx)
647 checkFileSize(t, ctx, zoneId, fileName, 1600)
648 checkFileByteCount(t, ctx, zoneId, fileName, 'a', 100)
649 checkFileByteCount(t, ctx, zoneId, fileName, 'e', 100)
650}
651
652func jsonDeepEqual(d1 any, d2 any) bool {
653 if d1 == nil && d2 == nil {

Callers

nothing calls this directly

Calls 8

initDbFunction · 0.85
cleanupDbFunction · 0.85
checkFileByteCountFunction · 0.85
MakeFileMethod · 0.80
AppendDataMethod · 0.80
FlushCacheMethod · 0.80
checkFileSizeFunction · 0.70
WaitMethod · 0.65

Tested by

no test coverage detected