tests(bitswap) share code between the two large tests
License: MIT Signed-off-by: Brian Tiger Chow <brian@perfmode.com>
Brian Tiger Chow committed
Nov 20, 2014 at 00:02 UTC
5babfb975de888f312536c87a19c92bb5f334b06
1 file changed
+12
-46
exchange/bitswap/bitswap_test.go
+12
-46
@@ -87,58 +87,27 @@ func TestGetBlockFromPeerAfterPeerAnnounces(t *testing.T) {
87
}
88
}
89
90
-func TestSwarm(t *testing.T) {
90
+func TestLargeSwarm(t *testing.T) {
91
if testing.Short() {
92
t.SkipNow()
93
}
94
- net := tn.VirtualNetwork()
95
- rs := mock.VirtualRoutingServer()
96
- sg := NewSessionGenerator(net, rs)
97
- bg := NewBlockGenerator()
98
-
99
- t.Log("Create a ton of instances, and just a few blocks")
100
-
94
+ t.Parallel()
95
numInstances := 500
96
numBlocks := 2
97
+ PerformDistributionTest(t, numInstances, numBlocks)
98
+}
99
104
- instances := sg.Instances(numInstances)
105
- blocks := bg.Blocks(numBlocks)
106
-
107
- t.Log("Give the blocks to the first instance")
108
-
109
- first := instances[0]
110
- for _, b := range blocks {
111
- first.blockstore.Put(b)
112
- first.exchange.HasBlock(context.Background(), *b)
113
- rs.Announce(first.peer, b.Key())
114
- }
115
-
116
- t.Log("Distribute!")
117
-
118
- var wg sync.WaitGroup
119
-
120
- for _, inst := range instances {
121
- for _, b := range blocks {
122
- wg.Add(1)
123
- // NB: executing getOrFail concurrently puts tremendous pressure on
124
- // the goroutine scheduler
125
- getOrFail(inst, b, t, &wg)
126
- }
127
- }
128
- wg.Wait()
129
-
130
- t.Log("Verify!")
131
-
132
- for _, inst := range instances {
133
- for _, b := range blocks {
134
- if _, err := inst.blockstore.Get(b.Key()); err != nil {
135
- t.Fatal(err)
136
- }
137
- }
100
+func TestLargeFile(t *testing.T) {
101
+ if testing.Short() {
102
+ t.SkipNow()
103
}
104
+ t.Parallel()
105
+ numInstances := 10
106
+ numBlocks := 100
107
+ PerformDistributionTest(t, numInstances, numBlocks)
108
}
109
141
-func TestLargeFile(t *testing.T) {
110
+func PerformDistributionTest(t *testing.T, numInstances, numBlocks int) {
111
if testing.Short() {
112
t.SkipNow()
113
}
@@ -149,9 +118,6 @@ func TestLargeFile(t *testing.T) {
118
119
t.Log("Test a few nodes trying to get one file with a lot of blocks")
120
152
- numInstances := 10
153
- numBlocks := 100
154
-
121
instances := sg.Instances(numInstances)
122
blocks := bg.Blocks(numBlocks)
123