-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproduce_consume_test.go
65 lines (53 loc) · 1.63 KB
/
produce_consume_test.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
package itest
import (
"context"
"testing"
"time"
shell "github.com/ipfs/go-ipfs-api"
"github.com/stretchr/testify/suite"
"github.com/areknoster/public-distributed-commit-log/ipns"
ipfsstorage "github.com/areknoster/public-distributed-commit-log/storage/message/ipfs"
"github.com/areknoster/public-distributed-commit-log/storage/pbcodec"
"github.com/areknoster/public-distributed-commit-log/test/testpb"
)
type MemoryProduceConsumeTestSuite struct {
ProduceConsumeTestSuite
}
func TestMemoryProduceConsumeTestSuite(t *testing.T) {
suite.Run(t, new(MemoryProduceConsumeTestSuite))
}
type LocalDaemonProduceConsumeTestSuite struct {
ProduceConsumeTestSuite
sh *shell.Shell
}
func (s *LocalDaemonProduceConsumeTestSuite) SetupSuite() {
s.sh = shell.NewShell("localhost:5001")
s.setupMessageStorage()
s.setupIPNS()
s.ProduceConsumeTestSuite.SetupSuite()
s.waitForDaemon()
}
func (s *LocalDaemonProduceConsumeTestSuite) waitForDaemon() {
s.T().Log("wait for daemon to start responding")
for i := 0; i < 5; i++ {
if _, err := s.messageStorage.Write(context.Background(), &testpb.Message{}); err == nil {
return
}
time.Sleep(3 * time.Second)
}
s.Fail("daemon doesn't respond")
}
func (s *LocalDaemonProduceConsumeTestSuite) setupIPNS() {
ipnsMgr, err := ipns.NewIPNSManager(s.sh)
s.Require().NoError(err)
s.ipnsMgr = ipnsMgr
}
func (s *LocalDaemonProduceConsumeTestSuite) setupMessageStorage() {
s.messageStorage = ipfsstorage.NewStorage(s.sh, pbcodec.Json{})
}
func TestLocalDaemonProduceConsumeTestSuite(t *testing.T) {
if testing.Short() {
t.Skip("skipping ")
}
suite.Run(t, new(LocalDaemonProduceConsumeTestSuite))
}