cheapcash/writer_test.go

40 lines
590 B
Go
Raw Normal View History

2021-11-16 04:56:33 +00:00
package cheapcash_test
import (
"sync"
"testing"
"github.com/aldy505/cheapcash"
)
func TestWrite(t *testing.T) {
c := cheapcash.Default()
err := c.Write("key", []byte("value"))
if err != nil {
t.Error("an error was thrown:", err)
}
}
2021-11-16 05:01:41 +00:00
func TestWrite_Concurrency(t *testing.T) {
2021-11-16 04:56:33 +00:00
c := cheapcash.Default()
2021-11-16 05:01:41 +00:00
var wg sync.WaitGroup
2021-11-16 04:56:33 +00:00
2021-11-16 05:01:41 +00:00
writeFunc := func() {
2021-11-16 04:56:33 +00:00
err := c.Write("key1", []byte("value1"))
if err != nil {
t.Error("an error was thrown:", err)
}
2021-11-16 05:01:41 +00:00
wg.Done()
2021-11-16 04:56:33 +00:00
}
wg.Add(5)
2021-11-16 05:01:41 +00:00
go writeFunc()
go writeFunc()
go writeFunc()
go writeFunc()
go writeFunc()
2021-11-16 04:56:33 +00:00
2021-11-16 05:01:41 +00:00
wg.Wait()
2021-11-16 04:56:33 +00:00
}