Skip to content

Commit

Permalink
Test history file cache
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippMatthes committed Apr 26, 2024
1 parent e88966e commit dd7977a
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions histories/cache_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package histories

import (
"fmt"
"io/ioutil"
"sync"
"testing"
"time"
)

func TestHistoryFileConcurrentWrite(t *testing.T) {
var concurrentWrites uint = 0
tempDir, err := ioutil.TempDir("", "")
if err != nil {
t.Errorf(err.Error())
}
mockFilePath := fmt.Sprintf("%s/h.json", tempDir)

var wg sync.WaitGroup
for {
if concurrentWrites > 10_000 {
break
}
wg.Add(1)
go func() {
appendToHistoryFile(mockFilePath, HistoryCycle{
StartTime: time.Now(), // Just to have some variation in the writes
})
wg.Done()
}()
concurrentWrites += 1
}
wg.Wait()
}

0 comments on commit dd7977a

Please sign in to comment.