MCPcopy Create free account
hub / github.com/CPChain/chain / testHeaderConcurrentAbortion

Function testHeaderConcurrentAbortion

core/block_validator_test.go:177–230  ·  view source on GitHub ↗
(t *testing.T, threads int)

Source from the content-addressed store, hash-verified

175func TestHeaderConcurrentAbortion32(t *testing.T) { testHeaderConcurrentAbortion(t, 32) }
176
177func testHeaderConcurrentAbortion(t *testing.T, threads int) {
178 // Create a simple chain to verify
179
180 var (
181 testdb = database.NewMemDatabase()
182 )
183
184 genesis := DefaultGenesisBlock()
185 genesisBlock := genesis.MustCommit(testdb)
186
187 remoteDB := database.NewIpfsDbWithAdapter(database.NewFakeIpfsAdapter())
188
189 config := configs.ChainConfigInfo().Dpor
190 d := dpor.NewFaker(config, testdb)
191
192 blocks, _ := GenerateChain(genesis.Config, genesisBlock, d, testdb, remoteDB, 8, nil)
193
194 headers := make([]*types.Header, len(blocks))
195 seals := make([]bool, len(blocks))
196
197 for i, block := range blocks {
198 headers[i] = block.Header()
199 seals[i] = true
200 }
201 // Set the number of threads to verify on
202 old := runtime.GOMAXPROCS(threads)
203 defer runtime.GOMAXPROCS(old)
204
205 engine := dpor.NewFakeDelayer(config, testdb, time.Millisecond)
206 // Start the verifications and immediately abort
207 chain, _ := NewBlockChain(testdb, nil, genesis.Config, engine, vm.Config{}, remoteDB, nil)
208 defer chain.Stop()
209
210 abort, results := chain.engine.VerifyHeaders(chain, headers, seals, headers)
211 close(abort)
212
213 // Deplete the results channel
214 verified := 0
215 for depleted := false; !depleted; {
216 select {
217 case result := <-results:
218 if result != nil {
219 t.Errorf("header %d: validation failed: %v", verified, result)
220 }
221 verified++
222 case <-time.After(50 * time.Millisecond):
223 depleted = true
224 }
225 }
226 // Check that abortion was honored by not processing too many POWs
227 if verified > 3*threads {
228 t.Errorf("verification count too large: have %d, want below %d", verified, 3*threads)
229 }
230}

Calls 8

StopMethod · 0.95
DefaultGenesisBlockFunction · 0.85
GenerateChainFunction · 0.85
NewBlockChainFunction · 0.85
MustCommitMethod · 0.80
ChainConfigInfoMethod · 0.80
HeaderMethod · 0.80
VerifyHeadersMethod · 0.65

Tested by

no test coverage detected