-
Notifications
You must be signed in to change notification settings - Fork 0
/
engine_suite.go
77 lines (70 loc) · 1.24 KB
/
engine_suite.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package engine
import (
"bytes"
"context"
"github.com/stretchr/testify/suite"
"github.com/youngfs/youngfs/pkg/util/randutil"
"io"
"sync"
)
type EngineSuite struct {
suite.Suite
Engine Engine
}
func (s *EngineSuite) TestEngine() {
s.NotNil(s.Engine)
ctx := context.Background()
const (
size = 1024
chunkSize = (256 + 64) * 1024
)
type chunk struct {
key string
body []byte
}
chunks := make([]chunk, size)
wg := &sync.WaitGroup{}
for i := range size {
wg.Add(1)
go func() {
b := randutil.RandByte(chunkSize)
id, err := s.Engine.PutChunk(ctx, bytes.NewReader(b))
s.Nil(err)
chunks[i] = chunk{id, b}
wg.Done()
}()
}
wg.Wait()
for i := range size {
wg.Add(1)
go func() {
reader, err := s.Engine.GetChunk(ctx, chunks[i].key)
s.Nil(err)
defer func() { _ = reader.Close() }()
b, err := io.ReadAll(reader)
s.Nil(err)
s.Equal(chunks[i].body, b)
wg.Done()
}()
}
wg.Wait()
for i := range size {
wg.Add(1)
go func() {
err := s.Engine.DeleteChunk(ctx, chunks[i].key)
s.Nil(err)
wg.Done()
}()
}
wg.Wait()
for i := range size {
wg.Add(1)
go func() {
reader, err := s.Engine.GetChunk(ctx, chunks[i].key)
s.NotNil(err)
s.Nil(reader)
wg.Done()
}()
}
wg.Wait()
}