Skip to content

Commit 9785a3e

Browse files
committed
fix: soc test
1 parent 560c2a0 commit 9785a3e

3 files changed

Lines changed: 26 additions & 4 deletions

File tree

pkg/api/api_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,7 @@ type chanStorer struct {
633633
lock sync.Mutex
634634
chunks map[string]struct{}
635635
quit chan struct{}
636+
subs []func(chunk swarm.Chunk)
636637
}
637638

638639
func newChanStore(cc <-chan *pusher.Op) *chanStorer {
@@ -650,6 +651,9 @@ func (c *chanStorer) drain(cc <-chan *pusher.Op) {
650651
case op := <-cc:
651652
c.lock.Lock()
652653
c.chunks[op.Chunk.Address().ByteString()] = struct{}{}
654+
for _, h := range c.subs {
655+
h(op.Chunk)
656+
}
653657
c.lock.Unlock()
654658
op.Err <- nil
655659
case <-c.quit:
@@ -670,6 +674,12 @@ func (c *chanStorer) Has(addr swarm.Address) bool {
670674
return ok
671675
}
672676

677+
func (c *chanStorer) Subscribe(f func(chunk swarm.Chunk)) {
678+
c.lock.Lock()
679+
defer c.lock.Unlock()
680+
c.subs = append(c.subs, f)
681+
}
682+
673683
func createRedistributionAgentService(
674684
t *testing.T,
675685
addr swarm.Address,

pkg/api/soc_test.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package api_test
66

77
import (
88
"bytes"
9+
"context"
910
"encoding/hex"
1011
"fmt"
1112
"io"
@@ -74,13 +75,20 @@ func TestSOC(t *testing.T) {
7475

7576
t.Run("ok", func(t *testing.T) {
7677
s := testingsoc.GenerateMockSOC(t, testData)
77-
client, _, _, _ := newTestServer(t, testServerOptions{
78+
client, _, _, chanStore := newTestServer(t, testServerOptions{
7879
Storer: mockStorer,
7980
Post: newTestPostService(),
8081
DirectUpload: true,
8182
})
83+
84+
chanStore.Subscribe(func(ch swarm.Chunk) {
85+
err := mockStorer.Put(context.Background(), ch)
86+
if err != nil {
87+
t.Fatal(err)
88+
}
89+
})
90+
8291
jsonhttptest.Request(t, client, http.MethodPost, socResource(hex.EncodeToString(s.Owner), hex.EncodeToString(s.ID), hex.EncodeToString(s.Signature)), http.StatusCreated,
83-
jsonhttptest.WithRequestHeader(api.SwarmPinHeader, "true"),
8492
jsonhttptest.WithRequestHeader(api.SwarmPostageBatchIdHeader, batchOkStr),
8593
jsonhttptest.WithRequestBody(bytes.NewReader(s.WrappedChunk.Data())),
8694
jsonhttptest.WithExpectedJSONResponse(api.SocPostResponse{

pkg/storer/mock/mockstorer.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import (
1010
"time"
1111

1212
"github.com/ethersphere/bee/v2/pkg/pusher"
13-
storage "github.com/ethersphere/bee/v2/pkg/storage"
13+
"github.com/ethersphere/bee/v2/pkg/storage"
1414
"github.com/ethersphere/bee/v2/pkg/storage/inmemchunkstore"
15-
storer "github.com/ethersphere/bee/v2/pkg/storer"
15+
"github.com/ethersphere/bee/v2/pkg/storer"
1616
"github.com/ethersphere/bee/v2/pkg/swarm"
1717
"go.uber.org/atomic"
1818
)
@@ -231,3 +231,7 @@ func (m *mockStorer) DebugInfo(_ context.Context) (storer.Info, error) {
231231
func (m *mockStorer) NeighborhoodsStat(ctx context.Context) ([]*storer.NeighborhoodStat, error) {
232232
return nil, nil
233233
}
234+
235+
func (m *mockStorer) Put(ctx context.Context, ch swarm.Chunk) error {
236+
return m.chunkStore.Put(ctx, ch)
237+
}

0 commit comments

Comments
 (0)