added a new test for a dhthell scenario that was failing
Jeromy committed
Nov 19, 2014 at 10:13 UTC
4d1447589c61bb42d853f61b9ba36aa2181335b8
2 files changed
+55
-6
exchange/bitswap/bitswap.go
+3
-5
@@ -128,7 +128,7 @@ func (bs *bitswap) sendWantListTo(ctx context.Context, peers <-chan peer.Peer) e
128
log.Event(ctx, "DialPeer", p)
129
err := bs.sender.DialPeer(ctx, p)
130
if err != nil {
131
- log.Errorf("Error sender.DialPeer(%s)", p)
131
+ log.Errorf("Error sender.DialPeer(%s): %s", p, err)
132
return
133
}
134
@@ -153,10 +153,8 @@ func (bs *bitswap) sendWantListTo(ctx context.Context, peers <-chan peer.Peer) e
153
154
func (bs *bitswap) run(ctx context.Context) {
155
156
- const batchDelay = time.Millisecond * 3 // Time to wait before sending out wantlists to better batch up requests
157
- const numKeysPerBatch = 10
158
- const maxProvidersPerRequest = 6
159
- const rebroadcastPeriod = time.Second * 5 // Every so often, we should resend out our current want list
156
+ // Every so often, we should resend out our current want list
157
+ rebroadcastTime := time.Second * 5
158
159
var providers <-chan peer.Peer // NB: must be initialized to zero value
160
broadcastSignal := time.After(rebroadcastPeriod)
exchange/bitswap/bitswap_test.go
+52
-1
@@ -100,7 +100,7 @@ func TestSwarm(t *testing.T) {
100
101
t.Log("Create a ton of instances, and just a few blocks")
102
103
- numInstances := 5
103
+ numInstances := 500
104
numBlocks := 2
105
106
instances := sg.Instances(numInstances)
@@ -140,6 +140,57 @@ func TestSwarm(t *testing.T) {
140
}
141
}
142
143
+func TestLargeFile(t *testing.T) {
144
+ if testing.Short() {
145
+ t.SkipNow()
146
+ }
147
+ net := tn.VirtualNetwork()
148
+ rs := mock.VirtualRoutingServer()
149
+ sg := NewSessionGenerator(net, rs)
150
+ bg := NewBlockGenerator()
151
+
152
+ t.Log("Test a few nodes trying to get one file with a lot of blocks")
153
+
154
+ numInstances := 10
155
+ numBlocks := 100
156
+
157
+ instances := sg.Instances(numInstances)
158
+ blocks := bg.Blocks(numBlocks)
159
+
160
+ t.Log("Give the blocks to the first instance")
161
+
162
+ first := instances[0]
163
+ for _, b := range blocks {
164
+ first.blockstore.Put(b)
165
+ first.exchange.HasBlock(context.Background(), *b)
166
+ rs.Announce(first.peer, b.Key())
167
+ }
168
+
169
+ t.Log("Distribute!")
170
+
171
+ var wg sync.WaitGroup
172
+
173
+ for _, inst := range instances {
174
+ for _, b := range blocks {
175
+ wg.Add(1)
176
+ // NB: executing getOrFail concurrently puts tremendous pressure on
177
+ // the goroutine scheduler
178
+ getOrFail(inst, b, t, &wg)
179
+ }
180
+ }
181
+ wg.Wait()
182
+
183
+ t.Log("Verify!")
184
+
185
+ for _, inst := range instances {
186
+ for _, b := range blocks {
187
+ if _, err := inst.blockstore.Get(b.Key()); err != nil {
188
+ t.Fatal(err)
189
+ }
190
+ }
191
+ }
192
+}
193
+
194
func getOrFail(bitswap instance, b *blocks.Block, t *testing.T, wg *sync.WaitGroup) {
195
if _, err := bitswap.blockstore.Get(b.Key()); err != nil {
196
_, err := bitswap.exchange.GetBlock(context.Background(), b.Key())