(t *testing.T)
| 610 | } |
| 611 | |
| 612 | func 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 | |
| 652 | func jsonDeepEqual(d1 any, d2 any) bool { |
| 653 | if d1 == nil && d2 == nil { |
nothing calls this directly
no test coverage detected