Skip to content

Commit c055ed1

Browse files
committed
test(provider): honor cancellation in map storage
1 parent f98a9ce commit c055ed1

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

internal/blobtesting/map.go

+28
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ type mapStorage struct {
3333
}
3434

3535
func (s *mapStorage) GetCapacity(ctx context.Context) (blob.Capacity, error) {
36+
if err := ctx.Err(); err != nil {
37+
return blob.Capacity{}, errors.Wrap(err, "get capacity failed")
38+
}
39+
3640
if s.limit < 0 {
3741
return blob.Capacity{}, blob.ErrNotAVolume
3842
}
@@ -47,6 +51,10 @@ func (s *mapStorage) GetCapacity(ctx context.Context) (blob.Capacity, error) {
4751
}
4852

4953
func (s *mapStorage) GetBlob(ctx context.Context, id blob.ID, offset, length int64, output blob.OutputBuffer) error {
54+
if err := ctx.Err(); err != nil {
55+
return errors.Wrap(err, "get blob failed")
56+
}
57+
5058
s.mutex.RLock()
5159
defer s.mutex.RUnlock()
5260

@@ -82,6 +90,10 @@ func (s *mapStorage) GetBlob(ctx context.Context, id blob.ID, offset, length int
8290
}
8391

8492
func (s *mapStorage) GetMetadata(ctx context.Context, id blob.ID) (blob.Metadata, error) {
93+
if err := ctx.Err(); err != nil {
94+
return blob.Metadata{}, errors.Wrap(err, "get metadata failed")
95+
}
96+
8597
s.mutex.RLock()
8698
defer s.mutex.RUnlock()
8799

@@ -98,6 +110,10 @@ func (s *mapStorage) GetMetadata(ctx context.Context, id blob.ID) (blob.Metadata
98110
}
99111

100112
func (s *mapStorage) PutBlob(ctx context.Context, id blob.ID, data blob.Bytes, opts blob.PutOptions) error {
113+
if err := ctx.Err(); err != nil {
114+
return errors.Wrap(err, "pub blob failed")
115+
}
116+
101117
switch {
102118
case opts.HasRetentionOptions():
103119
return errors.Wrap(blob.ErrUnsupportedPutBlobOption, "blob-retention")
@@ -134,6 +150,10 @@ func (s *mapStorage) PutBlob(ctx context.Context, id blob.ID, data blob.Bytes, o
134150
}
135151

136152
func (s *mapStorage) DeleteBlob(ctx context.Context, id blob.ID) error {
153+
if err := ctx.Err(); err != nil {
154+
return errors.Wrap(err, "delete blob failed")
155+
}
156+
137157
s.mutex.Lock()
138158
defer s.mutex.Unlock()
139159

@@ -145,6 +165,10 @@ func (s *mapStorage) DeleteBlob(ctx context.Context, id blob.ID) error {
145165
}
146166

147167
func (s *mapStorage) ListBlobs(ctx context.Context, prefix blob.ID, callback func(blob.Metadata) error) error {
168+
if err := ctx.Err(); err != nil {
169+
return errors.Wrap(err, "list blobs failed")
170+
}
171+
148172
s.mutex.RLock()
149173

150174
keys := []blob.ID{}
@@ -184,6 +208,10 @@ func (s *mapStorage) ListBlobs(ctx context.Context, prefix blob.ID, callback fun
184208
}
185209

186210
func (s *mapStorage) TouchBlob(ctx context.Context, blobID blob.ID, threshold time.Duration) (time.Time, error) {
211+
if err := ctx.Err(); err != nil {
212+
return time.Time{}, errors.Wrap(err, "touch blob failed")
213+
}
214+
187215
s.mutex.Lock()
188216
defer s.mutex.Unlock()
189217

0 commit comments

Comments
 (0)