worker_test.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  1. // Copyright 2018 The go-ethereum Authors
  2. // This file is part of the go-ethereum library.
  3. //
  4. // The go-ethereum library is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Lesser General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // The go-ethereum library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public License
  15. // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
  16. package miner
  17. import (
  18. "math/big"
  19. "math/rand"
  20. "testing"
  21. "time"
  22. "github.com/ethereum/go-ethereum/accounts"
  23. "github.com/ethereum/go-ethereum/common"
  24. "github.com/ethereum/go-ethereum/consensus"
  25. "github.com/ethereum/go-ethereum/consensus/clique"
  26. "github.com/ethereum/go-ethereum/consensus/ethash"
  27. "github.com/ethereum/go-ethereum/core"
  28. "github.com/ethereum/go-ethereum/core/rawdb"
  29. "github.com/ethereum/go-ethereum/core/types"
  30. "github.com/ethereum/go-ethereum/core/vm"
  31. "github.com/ethereum/go-ethereum/crypto"
  32. "github.com/ethereum/go-ethereum/ethdb"
  33. "github.com/ethereum/go-ethereum/event"
  34. "github.com/ethereum/go-ethereum/params"
  35. )
  36. const (
  37. // testCode is the testing contract binary code which will initialises some
  38. // variables in constructor
  39. testCode = "0x60806040527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0060005534801561003457600080fd5b5060fc806100436000396000f3fe6080604052348015600f57600080fd5b506004361060325760003560e01c80630c4dae8814603757806398a213cf146053575b600080fd5b603d607e565b6040518082815260200191505060405180910390f35b607c60048036036020811015606757600080fd5b81019080803590602001909291905050506084565b005b60005481565b806000819055507fe9e44f9f7da8c559de847a3232b57364adc0354f15a2cd8dc636d54396f9587a6000546040518082815260200191505060405180910390a15056fea265627a7a723058208ae31d9424f2d0bc2a3da1a5dd659db2d71ec322a17db8f87e19e209e3a1ff4a64736f6c634300050a0032"
  40. // testGas is the gas required for contract deployment.
  41. testGas = 144109
  42. )
  43. var (
  44. // Test chain configurations
  45. testTxPoolConfig core.TxPoolConfig
  46. ethashChainConfig *params.ChainConfig
  47. cliqueChainConfig *params.ChainConfig
  48. // Test accounts
  49. testBankKey, _ = crypto.GenerateKey()
  50. testBankAddress = crypto.PubkeyToAddress(testBankKey.PublicKey)
  51. testBankFunds = big.NewInt(1000000000000000000)
  52. testUserKey, _ = crypto.GenerateKey()
  53. testUserAddress = crypto.PubkeyToAddress(testUserKey.PublicKey)
  54. // Test transactions
  55. pendingTxs []*types.Transaction
  56. newTxs []*types.Transaction
  57. testConfig = &Config{
  58. Recommit: time.Second,
  59. GasFloor: params.GenesisGasLimit,
  60. GasCeil: params.GenesisGasLimit,
  61. }
  62. )
  63. func init() {
  64. testTxPoolConfig = core.DefaultTxPoolConfig
  65. testTxPoolConfig.Journal = ""
  66. ethashChainConfig = params.TestChainConfig
  67. cliqueChainConfig = params.TestChainConfig
  68. cliqueChainConfig.Clique = &params.CliqueConfig{
  69. Period: 10,
  70. Epoch: 30000,
  71. }
  72. tx1, _ := types.SignTx(types.NewTransaction(0, testUserAddress, big.NewInt(1000), params.TxGas, nil, nil), types.HomesteadSigner{}, testBankKey)
  73. pendingTxs = append(pendingTxs, tx1)
  74. tx2, _ := types.SignTx(types.NewTransaction(1, testUserAddress, big.NewInt(1000), params.TxGas, nil, nil), types.HomesteadSigner{}, testBankKey)
  75. newTxs = append(newTxs, tx2)
  76. }
  77. // testWorkerBackend implements worker.Backend interfaces and wraps all information needed during the testing.
  78. type testWorkerBackend struct {
  79. db ethdb.Database
  80. txPool *core.TxPool
  81. chain *core.BlockChain
  82. testTxFeed event.Feed
  83. genesis *core.Genesis
  84. uncleBlock *types.Block
  85. }
  86. func newTestWorkerBackend(t *testing.T, chainConfig *params.ChainConfig, engine consensus.Engine, db ethdb.Database, n int) *testWorkerBackend {
  87. var gspec = core.Genesis{
  88. Config: chainConfig,
  89. Alloc: core.GenesisAlloc{testBankAddress: {Balance: testBankFunds}},
  90. }
  91. switch e := engine.(type) {
  92. case *clique.Clique:
  93. gspec.ExtraData = make([]byte, 32+common.AddressLength+crypto.SignatureLength)
  94. copy(gspec.ExtraData[32:32+common.AddressLength], testBankAddress.Bytes())
  95. e.Authorize(testBankAddress, func(account accounts.Account, s string, data []byte) ([]byte, error) {
  96. return crypto.Sign(crypto.Keccak256(data), testBankKey)
  97. })
  98. case *ethash.Ethash:
  99. default:
  100. t.Fatalf("unexpected consensus engine type: %T", engine)
  101. }
  102. genesis := gspec.MustCommit(db)
  103. chain, _ := core.NewBlockChain(db, &core.CacheConfig{TrieDirtyDisabled: true}, gspec.Config, engine, vm.Config{}, nil)
  104. txpool := core.NewTxPool(testTxPoolConfig, chainConfig, chain)
  105. // Generate a small n-block chain and an uncle block for it
  106. if n > 0 {
  107. blocks, _ := core.GenerateChain(chainConfig, genesis, engine, db, n, func(i int, gen *core.BlockGen) {
  108. gen.SetCoinbase(testBankAddress)
  109. })
  110. if _, err := chain.InsertChain(blocks); err != nil {
  111. t.Fatalf("failed to insert origin chain: %v", err)
  112. }
  113. }
  114. parent := genesis
  115. if n > 0 {
  116. parent = chain.GetBlockByHash(chain.CurrentBlock().ParentHash())
  117. }
  118. blocks, _ := core.GenerateChain(chainConfig, parent, engine, db, 1, func(i int, gen *core.BlockGen) {
  119. gen.SetCoinbase(testUserAddress)
  120. })
  121. return &testWorkerBackend{
  122. db: db,
  123. chain: chain,
  124. txPool: txpool,
  125. genesis: &gspec,
  126. uncleBlock: blocks[0],
  127. }
  128. }
  129. func (b *testWorkerBackend) BlockChain() *core.BlockChain { return b.chain }
  130. func (b *testWorkerBackend) TxPool() *core.TxPool { return b.txPool }
  131. func (b *testWorkerBackend) PostChainEvents(events []interface{}) {
  132. b.chain.PostChainEvents(events, nil)
  133. }
  134. func (b *testWorkerBackend) newRandomUncle() *types.Block {
  135. var parent *types.Block
  136. cur := b.chain.CurrentBlock()
  137. if cur.NumberU64() == 0 {
  138. parent = b.chain.Genesis()
  139. } else {
  140. parent = b.chain.GetBlockByHash(b.chain.CurrentBlock().ParentHash())
  141. }
  142. blocks, _ := core.GenerateChain(b.chain.Config(), parent, b.chain.Engine(), b.db, 1, func(i int, gen *core.BlockGen) {
  143. var addr common.Address
  144. rand.Read(addr.Bytes())
  145. gen.SetCoinbase(addr)
  146. })
  147. return blocks[0]
  148. }
  149. func (b *testWorkerBackend) newRandomTx(creation bool) *types.Transaction {
  150. var tx *types.Transaction
  151. if creation {
  152. tx, _ = types.SignTx(types.NewContractCreation(b.txPool.Nonce(testBankAddress), big.NewInt(0), testGas, nil, common.FromHex(testCode)), types.HomesteadSigner{}, testBankKey)
  153. } else {
  154. tx, _ = types.SignTx(types.NewTransaction(b.txPool.Nonce(testBankAddress), testUserAddress, big.NewInt(1000), params.TxGas, nil, nil), types.HomesteadSigner{}, testBankKey)
  155. }
  156. return tx
  157. }
  158. func newTestWorker(t *testing.T, chainConfig *params.ChainConfig, engine consensus.Engine, db ethdb.Database, blocks int) (*worker, *testWorkerBackend) {
  159. backend := newTestWorkerBackend(t, chainConfig, engine, db, blocks)
  160. backend.txPool.AddLocals(pendingTxs)
  161. w := newWorker(testConfig, chainConfig, engine, backend, new(event.TypeMux), nil)
  162. w.setEtherbase(testBankAddress)
  163. return w, backend
  164. }
  165. func TestGenerateBlockAndImportEthash(t *testing.T) {
  166. testGenerateBlockAndImport(t, false)
  167. }
  168. func TestGenerateBlockAndImportClique(t *testing.T) {
  169. testGenerateBlockAndImport(t, true)
  170. }
  171. func testGenerateBlockAndImport(t *testing.T, isClique bool) {
  172. var (
  173. engine consensus.Engine
  174. chainConfig *params.ChainConfig
  175. db = rawdb.NewMemoryDatabase()
  176. )
  177. if isClique {
  178. chainConfig = params.AllCliqueProtocolChanges
  179. engine = clique.New(chainConfig.Clique, db)
  180. } else {
  181. chainConfig = params.AllEthashProtocolChanges
  182. engine = ethash.NewFaker()
  183. }
  184. w, b := newTestWorker(t, chainConfig, engine, db, 0)
  185. defer w.close()
  186. db2 := rawdb.NewMemoryDatabase()
  187. b.genesis.MustCommit(db2)
  188. chain, _ := core.NewBlockChain(db2, nil, b.chain.Config(), engine, vm.Config{}, nil)
  189. defer chain.Stop()
  190. newBlock := make(chan struct{})
  191. listenNewBlock := func() {
  192. sub := w.mux.Subscribe(core.NewMinedBlockEvent{})
  193. defer sub.Unsubscribe()
  194. for item := range sub.Chan() {
  195. block := item.Data.(core.NewMinedBlockEvent).Block
  196. _, err := chain.InsertChain([]*types.Block{block})
  197. if err != nil {
  198. t.Fatalf("Failed to insert new mined block:%d, error:%v", block.NumberU64(), err)
  199. }
  200. newBlock <- struct{}{}
  201. }
  202. }
  203. // Ensure worker has finished initialization
  204. for {
  205. b := w.pendingBlock()
  206. if b != nil && b.NumberU64() == 1 {
  207. break
  208. }
  209. }
  210. w.start() // Start mining!
  211. // Ignore first 2 commits caused by start operation
  212. ignored := make(chan struct{}, 2)
  213. w.skipSealHook = func(task *task) bool {
  214. ignored <- struct{}{}
  215. return true
  216. }
  217. for i := 0; i < 2; i++ {
  218. <-ignored
  219. }
  220. go listenNewBlock()
  221. // Ignore empty commit here for less noise
  222. w.skipSealHook = func(task *task) bool {
  223. return len(task.receipts) == 0
  224. }
  225. for i := 0; i < 50; i++ {
  226. b.txPool.AddLocal(b.newRandomTx(true))
  227. b.txPool.AddLocal(b.newRandomTx(false))
  228. b.PostChainEvents([]interface{}{core.ChainSideEvent{Block: b.newRandomUncle()}})
  229. b.PostChainEvents([]interface{}{core.ChainSideEvent{Block: b.newRandomUncle()}})
  230. select {
  231. case <-newBlock:
  232. case <-time.NewTimer(time.Millisecond * 1500).C: // Worker needs 1s to include new changes.
  233. t.Fatalf("timeout")
  234. }
  235. }
  236. }
  237. func TestPendingStateAndBlockEthash(t *testing.T) {
  238. testPendingStateAndBlock(t, ethashChainConfig, ethash.NewFaker())
  239. }
  240. func TestPendingStateAndBlockClique(t *testing.T) {
  241. testPendingStateAndBlock(t, cliqueChainConfig, clique.New(cliqueChainConfig.Clique, rawdb.NewMemoryDatabase()))
  242. }
  243. func testPendingStateAndBlock(t *testing.T, chainConfig *params.ChainConfig, engine consensus.Engine) {
  244. defer engine.Close()
  245. w, b := newTestWorker(t, chainConfig, engine, rawdb.NewMemoryDatabase(), 0)
  246. defer w.close()
  247. // Ensure snapshot has been updated.
  248. time.Sleep(100 * time.Millisecond)
  249. block, state := w.pending()
  250. if block.NumberU64() != 1 {
  251. t.Errorf("block number mismatch: have %d, want %d", block.NumberU64(), 1)
  252. }
  253. if balance := state.GetBalance(testUserAddress); balance.Cmp(big.NewInt(1000)) != 0 {
  254. t.Errorf("account balance mismatch: have %d, want %d", balance, 1000)
  255. }
  256. b.txPool.AddLocals(newTxs)
  257. // Ensure the new tx events has been processed
  258. time.Sleep(100 * time.Millisecond)
  259. block, state = w.pending()
  260. if balance := state.GetBalance(testUserAddress); balance.Cmp(big.NewInt(2000)) != 0 {
  261. t.Errorf("account balance mismatch: have %d, want %d", balance, 2000)
  262. }
  263. }
  264. func TestEmptyWorkEthash(t *testing.T) {
  265. testEmptyWork(t, ethashChainConfig, ethash.NewFaker())
  266. }
  267. func TestEmptyWorkClique(t *testing.T) {
  268. testEmptyWork(t, cliqueChainConfig, clique.New(cliqueChainConfig.Clique, rawdb.NewMemoryDatabase()))
  269. }
  270. func testEmptyWork(t *testing.T, chainConfig *params.ChainConfig, engine consensus.Engine) {
  271. defer engine.Close()
  272. w, _ := newTestWorker(t, chainConfig, engine, rawdb.NewMemoryDatabase(), 0)
  273. defer w.close()
  274. var (
  275. taskCh = make(chan struct{}, 2)
  276. taskIndex int
  277. )
  278. checkEqual := func(t *testing.T, task *task, index int) {
  279. receiptLen, balance := 0, big.NewInt(0)
  280. if index == 1 {
  281. receiptLen, balance = 1, big.NewInt(1000)
  282. }
  283. if len(task.receipts) != receiptLen {
  284. t.Errorf("receipt number mismatch: have %d, want %d", len(task.receipts), receiptLen)
  285. }
  286. if task.state.GetBalance(testUserAddress).Cmp(balance) != 0 {
  287. t.Errorf("account balance mismatch: have %d, want %d", task.state.GetBalance(testUserAddress), balance)
  288. }
  289. }
  290. w.newTaskHook = func(task *task) {
  291. if task.block.NumberU64() == 1 {
  292. checkEqual(t, task, taskIndex)
  293. taskIndex += 1
  294. taskCh <- struct{}{}
  295. }
  296. }
  297. w.fullTaskHook = func() {
  298. time.Sleep(100 * time.Millisecond)
  299. }
  300. // Ensure worker has finished initialization
  301. for {
  302. b := w.pendingBlock()
  303. if b != nil && b.NumberU64() == 1 {
  304. break
  305. }
  306. }
  307. w.start()
  308. for i := 0; i < 2; i += 1 {
  309. select {
  310. case <-taskCh:
  311. case <-time.NewTimer(2 * time.Second).C:
  312. t.Error("new task timeout")
  313. }
  314. }
  315. }
  316. func TestStreamUncleBlock(t *testing.T) {
  317. ethash := ethash.NewFaker()
  318. defer ethash.Close()
  319. w, b := newTestWorker(t, ethashChainConfig, ethash, rawdb.NewMemoryDatabase(), 1)
  320. defer w.close()
  321. var taskCh = make(chan struct{})
  322. taskIndex := 0
  323. w.newTaskHook = func(task *task) {
  324. if task.block.NumberU64() == 2 {
  325. if taskIndex == 2 {
  326. have := task.block.Header().UncleHash
  327. want := types.CalcUncleHash([]*types.Header{b.uncleBlock.Header()})
  328. if have != want {
  329. t.Errorf("uncle hash mismatch: have %s, want %s", have.Hex(), want.Hex())
  330. }
  331. }
  332. taskCh <- struct{}{}
  333. taskIndex += 1
  334. }
  335. }
  336. w.skipSealHook = func(task *task) bool {
  337. return true
  338. }
  339. w.fullTaskHook = func() {
  340. time.Sleep(100 * time.Millisecond)
  341. }
  342. // Ensure worker has finished initialization
  343. for {
  344. b := w.pendingBlock()
  345. if b != nil && b.NumberU64() == 2 {
  346. break
  347. }
  348. }
  349. w.start()
  350. // Ignore the first two works
  351. for i := 0; i < 2; i += 1 {
  352. select {
  353. case <-taskCh:
  354. case <-time.NewTimer(time.Second).C:
  355. t.Error("new task timeout")
  356. }
  357. }
  358. b.PostChainEvents([]interface{}{core.ChainSideEvent{Block: b.uncleBlock}})
  359. select {
  360. case <-taskCh:
  361. case <-time.NewTimer(time.Second).C:
  362. t.Error("new task timeout")
  363. }
  364. }
  365. func TestRegenerateMiningBlockEthash(t *testing.T) {
  366. testRegenerateMiningBlock(t, ethashChainConfig, ethash.NewFaker())
  367. }
  368. func TestRegenerateMiningBlockClique(t *testing.T) {
  369. testRegenerateMiningBlock(t, cliqueChainConfig, clique.New(cliqueChainConfig.Clique, rawdb.NewMemoryDatabase()))
  370. }
  371. func testRegenerateMiningBlock(t *testing.T, chainConfig *params.ChainConfig, engine consensus.Engine) {
  372. defer engine.Close()
  373. w, b := newTestWorker(t, chainConfig, engine, rawdb.NewMemoryDatabase(), 0)
  374. defer w.close()
  375. var taskCh = make(chan struct{})
  376. taskIndex := 0
  377. w.newTaskHook = func(task *task) {
  378. if task.block.NumberU64() == 1 {
  379. if taskIndex == 2 {
  380. receiptLen, balance := 2, big.NewInt(2000)
  381. if len(task.receipts) != receiptLen {
  382. t.Errorf("receipt number mismatch: have %d, want %d", len(task.receipts), receiptLen)
  383. }
  384. if task.state.GetBalance(testUserAddress).Cmp(balance) != 0 {
  385. t.Errorf("account balance mismatch: have %d, want %d", task.state.GetBalance(testUserAddress), balance)
  386. }
  387. }
  388. taskCh <- struct{}{}
  389. taskIndex += 1
  390. }
  391. }
  392. w.skipSealHook = func(task *task) bool {
  393. return true
  394. }
  395. w.fullTaskHook = func() {
  396. time.Sleep(100 * time.Millisecond)
  397. }
  398. // Ensure worker has finished initialization
  399. for {
  400. b := w.pendingBlock()
  401. if b != nil && b.NumberU64() == 1 {
  402. break
  403. }
  404. }
  405. w.start()
  406. // Ignore the first two works
  407. for i := 0; i < 2; i += 1 {
  408. select {
  409. case <-taskCh:
  410. case <-time.NewTimer(time.Second).C:
  411. t.Error("new task timeout")
  412. }
  413. }
  414. b.txPool.AddLocals(newTxs)
  415. time.Sleep(time.Second)
  416. select {
  417. case <-taskCh:
  418. case <-time.NewTimer(time.Second).C:
  419. t.Error("new task timeout")
  420. }
  421. }
  422. func TestAdjustIntervalEthash(t *testing.T) {
  423. testAdjustInterval(t, ethashChainConfig, ethash.NewFaker())
  424. }
  425. func TestAdjustIntervalClique(t *testing.T) {
  426. testAdjustInterval(t, cliqueChainConfig, clique.New(cliqueChainConfig.Clique, rawdb.NewMemoryDatabase()))
  427. }
  428. func testAdjustInterval(t *testing.T, chainConfig *params.ChainConfig, engine consensus.Engine) {
  429. defer engine.Close()
  430. w, _ := newTestWorker(t, chainConfig, engine, rawdb.NewMemoryDatabase(), 0)
  431. defer w.close()
  432. w.skipSealHook = func(task *task) bool {
  433. return true
  434. }
  435. w.fullTaskHook = func() {
  436. time.Sleep(100 * time.Millisecond)
  437. }
  438. var (
  439. progress = make(chan struct{}, 10)
  440. result = make([]float64, 0, 10)
  441. index = 0
  442. start = false
  443. )
  444. w.resubmitHook = func(minInterval time.Duration, recommitInterval time.Duration) {
  445. // Short circuit if interval checking hasn't started.
  446. if !start {
  447. return
  448. }
  449. var wantMinInterval, wantRecommitInterval time.Duration
  450. switch index {
  451. case 0:
  452. wantMinInterval, wantRecommitInterval = 3*time.Second, 3*time.Second
  453. case 1:
  454. origin := float64(3 * time.Second.Nanoseconds())
  455. estimate := origin*(1-intervalAdjustRatio) + intervalAdjustRatio*(origin/0.8+intervalAdjustBias)
  456. wantMinInterval, wantRecommitInterval = 3*time.Second, time.Duration(estimate)*time.Nanosecond
  457. case 2:
  458. estimate := result[index-1]
  459. min := float64(3 * time.Second.Nanoseconds())
  460. estimate = estimate*(1-intervalAdjustRatio) + intervalAdjustRatio*(min-intervalAdjustBias)
  461. wantMinInterval, wantRecommitInterval = 3*time.Second, time.Duration(estimate)*time.Nanosecond
  462. case 3:
  463. wantMinInterval, wantRecommitInterval = time.Second, time.Second
  464. }
  465. // Check interval
  466. if minInterval != wantMinInterval {
  467. t.Errorf("resubmit min interval mismatch: have %v, want %v ", minInterval, wantMinInterval)
  468. }
  469. if recommitInterval != wantRecommitInterval {
  470. t.Errorf("resubmit interval mismatch: have %v, want %v", recommitInterval, wantRecommitInterval)
  471. }
  472. result = append(result, float64(recommitInterval.Nanoseconds()))
  473. index += 1
  474. progress <- struct{}{}
  475. }
  476. // Ensure worker has finished initialization
  477. for {
  478. b := w.pendingBlock()
  479. if b != nil && b.NumberU64() == 1 {
  480. break
  481. }
  482. }
  483. w.start()
  484. time.Sleep(time.Second)
  485. start = true
  486. w.setRecommitInterval(3 * time.Second)
  487. select {
  488. case <-progress:
  489. case <-time.NewTimer(time.Second).C:
  490. t.Error("interval reset timeout")
  491. }
  492. w.resubmitAdjustCh <- &intervalAdjust{inc: true, ratio: 0.8}
  493. select {
  494. case <-progress:
  495. case <-time.NewTimer(time.Second).C:
  496. t.Error("interval reset timeout")
  497. }
  498. w.resubmitAdjustCh <- &intervalAdjust{inc: false}
  499. select {
  500. case <-progress:
  501. case <-time.NewTimer(time.Second).C:
  502. t.Error("interval reset timeout")
  503. }
  504. w.setRecommitInterval(500 * time.Millisecond)
  505. select {
  506. case <-progress:
  507. case <-time.NewTimer(time.Second).C:
  508. t.Error("interval reset timeout")
  509. }
  510. }