worker_test.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  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. rand.Seed(time.Now().UnixNano())
  77. }
  78. // testWorkerBackend implements worker.Backend interfaces and wraps all information needed during the testing.
  79. type testWorkerBackend struct {
  80. db ethdb.Database
  81. txPool *core.TxPool
  82. chain *core.BlockChain
  83. testTxFeed event.Feed
  84. genesis *core.Genesis
  85. uncleBlock *types.Block
  86. }
  87. func newTestWorkerBackend(t *testing.T, chainConfig *params.ChainConfig, engine consensus.Engine, db ethdb.Database, n int) *testWorkerBackend {
  88. var gspec = core.Genesis{
  89. Config: chainConfig,
  90. Alloc: core.GenesisAlloc{testBankAddress: {Balance: testBankFunds}},
  91. }
  92. switch e := engine.(type) {
  93. case *clique.Clique:
  94. gspec.ExtraData = make([]byte, 32+common.AddressLength+crypto.SignatureLength)
  95. copy(gspec.ExtraData[32:32+common.AddressLength], testBankAddress.Bytes())
  96. e.Authorize(testBankAddress, func(account accounts.Account, s string, data []byte) ([]byte, error) {
  97. return crypto.Sign(crypto.Keccak256(data), testBankKey)
  98. })
  99. case *ethash.Ethash:
  100. default:
  101. t.Fatalf("unexpected consensus engine type: %T", engine)
  102. }
  103. genesis := gspec.MustCommit(db)
  104. chain, _ := core.NewBlockChain(db, &core.CacheConfig{TrieDirtyDisabled: true}, gspec.Config, engine, vm.Config{}, nil)
  105. txpool := core.NewTxPool(testTxPoolConfig, chainConfig, chain)
  106. // Generate a small n-block chain and an uncle block for it
  107. if n > 0 {
  108. blocks, _ := core.GenerateChain(chainConfig, genesis, engine, db, n, func(i int, gen *core.BlockGen) {
  109. gen.SetCoinbase(testBankAddress)
  110. })
  111. if _, err := chain.InsertChain(blocks); err != nil {
  112. t.Fatalf("failed to insert origin chain: %v", err)
  113. }
  114. }
  115. parent := genesis
  116. if n > 0 {
  117. parent = chain.GetBlockByHash(chain.CurrentBlock().ParentHash())
  118. }
  119. blocks, _ := core.GenerateChain(chainConfig, parent, engine, db, 1, func(i int, gen *core.BlockGen) {
  120. gen.SetCoinbase(testUserAddress)
  121. })
  122. return &testWorkerBackend{
  123. db: db,
  124. chain: chain,
  125. txPool: txpool,
  126. genesis: &gspec,
  127. uncleBlock: blocks[0],
  128. }
  129. }
  130. func (b *testWorkerBackend) BlockChain() *core.BlockChain { return b.chain }
  131. func (b *testWorkerBackend) TxPool() *core.TxPool { return b.txPool }
  132. func (b *testWorkerBackend) PostChainEvents(events []interface{}) {
  133. b.chain.PostChainEvents(events, nil)
  134. }
  135. func (b *testWorkerBackend) newRandomUncle() *types.Block {
  136. var parent *types.Block
  137. cur := b.chain.CurrentBlock()
  138. if cur.NumberU64() == 0 {
  139. parent = b.chain.Genesis()
  140. } else {
  141. parent = b.chain.GetBlockByHash(b.chain.CurrentBlock().ParentHash())
  142. }
  143. blocks, _ := core.GenerateChain(b.chain.Config(), parent, b.chain.Engine(), b.db, 1, func(i int, gen *core.BlockGen) {
  144. var addr = make([]byte, common.AddressLength)
  145. rand.Read(addr)
  146. gen.SetCoinbase(common.BytesToAddress(addr))
  147. })
  148. return blocks[0]
  149. }
  150. func (b *testWorkerBackend) newRandomTx(creation bool) *types.Transaction {
  151. var tx *types.Transaction
  152. if creation {
  153. tx, _ = types.SignTx(types.NewContractCreation(b.txPool.Nonce(testBankAddress), big.NewInt(0), testGas, nil, common.FromHex(testCode)), types.HomesteadSigner{}, testBankKey)
  154. } else {
  155. tx, _ = types.SignTx(types.NewTransaction(b.txPool.Nonce(testBankAddress), testUserAddress, big.NewInt(1000), params.TxGas, nil, nil), types.HomesteadSigner{}, testBankKey)
  156. }
  157. return tx
  158. }
  159. func newTestWorker(t *testing.T, chainConfig *params.ChainConfig, engine consensus.Engine, db ethdb.Database, blocks int) (*worker, *testWorkerBackend) {
  160. backend := newTestWorkerBackend(t, chainConfig, engine, db, blocks)
  161. backend.txPool.AddLocals(pendingTxs)
  162. w := newWorker(testConfig, chainConfig, engine, backend, new(event.TypeMux), nil)
  163. w.setEtherbase(testBankAddress)
  164. return w, backend
  165. }
  166. func TestGenerateBlockAndImportEthash(t *testing.T) {
  167. testGenerateBlockAndImport(t, false)
  168. }
  169. func TestGenerateBlockAndImportClique(t *testing.T) {
  170. testGenerateBlockAndImport(t, true)
  171. }
  172. func testGenerateBlockAndImport(t *testing.T, isClique bool) {
  173. var (
  174. engine consensus.Engine
  175. chainConfig *params.ChainConfig
  176. db = rawdb.NewMemoryDatabase()
  177. )
  178. if isClique {
  179. chainConfig = params.AllCliqueProtocolChanges
  180. chainConfig.Clique = &params.CliqueConfig{Period: 1, Epoch: 30000}
  181. engine = clique.New(chainConfig.Clique, db)
  182. } else {
  183. chainConfig = params.AllEthashProtocolChanges
  184. engine = ethash.NewFaker()
  185. }
  186. w, b := newTestWorker(t, chainConfig, engine, db, 0)
  187. defer w.close()
  188. db2 := rawdb.NewMemoryDatabase()
  189. b.genesis.MustCommit(db2)
  190. chain, _ := core.NewBlockChain(db2, nil, b.chain.Config(), engine, vm.Config{}, nil)
  191. defer chain.Stop()
  192. newBlock := make(chan struct{})
  193. listenNewBlock := func() {
  194. sub := w.mux.Subscribe(core.NewMinedBlockEvent{})
  195. defer sub.Unsubscribe()
  196. for item := range sub.Chan() {
  197. block := item.Data.(core.NewMinedBlockEvent).Block
  198. _, err := chain.InsertChain([]*types.Block{block})
  199. if err != nil {
  200. t.Fatalf("Failed to insert new mined block:%d, error:%v", block.NumberU64(), err)
  201. }
  202. newBlock <- struct{}{}
  203. }
  204. }
  205. // Ensure worker has finished initialization
  206. for {
  207. b := w.pendingBlock()
  208. if b != nil && b.NumberU64() == 1 {
  209. break
  210. }
  211. }
  212. w.start() // Start mining!
  213. // Ignore first 2 commits caused by start operation
  214. ignored := make(chan struct{}, 2)
  215. w.skipSealHook = func(task *task) bool {
  216. ignored <- struct{}{}
  217. return true
  218. }
  219. for i := 0; i < 2; i++ {
  220. <-ignored
  221. }
  222. go listenNewBlock()
  223. // Ignore empty commit here for less noise
  224. w.skipSealHook = func(task *task) bool {
  225. return len(task.receipts) == 0
  226. }
  227. for i := 0; i < 5; i++ {
  228. b.txPool.AddLocal(b.newRandomTx(true))
  229. b.txPool.AddLocal(b.newRandomTx(false))
  230. b.PostChainEvents([]interface{}{core.ChainSideEvent{Block: b.newRandomUncle()}})
  231. b.PostChainEvents([]interface{}{core.ChainSideEvent{Block: b.newRandomUncle()}})
  232. select {
  233. case <-newBlock:
  234. case <-time.NewTimer(3 * time.Second).C: // Worker needs 1s to include new changes.
  235. t.Fatalf("timeout")
  236. }
  237. }
  238. }
  239. func TestPendingStateAndBlockEthash(t *testing.T) {
  240. testPendingStateAndBlock(t, ethashChainConfig, ethash.NewFaker())
  241. }
  242. func TestPendingStateAndBlockClique(t *testing.T) {
  243. testPendingStateAndBlock(t, cliqueChainConfig, clique.New(cliqueChainConfig.Clique, rawdb.NewMemoryDatabase()))
  244. }
  245. func testPendingStateAndBlock(t *testing.T, chainConfig *params.ChainConfig, engine consensus.Engine) {
  246. defer engine.Close()
  247. w, b := newTestWorker(t, chainConfig, engine, rawdb.NewMemoryDatabase(), 0)
  248. defer w.close()
  249. // Ensure snapshot has been updated.
  250. time.Sleep(100 * time.Millisecond)
  251. block, state := w.pending()
  252. if block.NumberU64() != 1 {
  253. t.Errorf("block number mismatch: have %d, want %d", block.NumberU64(), 1)
  254. }
  255. if balance := state.GetBalance(testUserAddress); balance.Cmp(big.NewInt(1000)) != 0 {
  256. t.Errorf("account balance mismatch: have %d, want %d", balance, 1000)
  257. }
  258. b.txPool.AddLocals(newTxs)
  259. // Ensure the new tx events has been processed
  260. time.Sleep(100 * time.Millisecond)
  261. block, state = w.pending()
  262. if balance := state.GetBalance(testUserAddress); balance.Cmp(big.NewInt(2000)) != 0 {
  263. t.Errorf("account balance mismatch: have %d, want %d", balance, 2000)
  264. }
  265. }
  266. func TestEmptyWorkEthash(t *testing.T) {
  267. testEmptyWork(t, ethashChainConfig, ethash.NewFaker())
  268. }
  269. func TestEmptyWorkClique(t *testing.T) {
  270. testEmptyWork(t, cliqueChainConfig, clique.New(cliqueChainConfig.Clique, rawdb.NewMemoryDatabase()))
  271. }
  272. func testEmptyWork(t *testing.T, chainConfig *params.ChainConfig, engine consensus.Engine) {
  273. defer engine.Close()
  274. w, _ := newTestWorker(t, chainConfig, engine, rawdb.NewMemoryDatabase(), 0)
  275. defer w.close()
  276. var (
  277. taskCh = make(chan struct{}, 2)
  278. taskIndex int
  279. )
  280. checkEqual := func(t *testing.T, task *task, index int) {
  281. receiptLen, balance := 0, big.NewInt(0)
  282. if index == 1 {
  283. receiptLen, balance = 1, big.NewInt(1000)
  284. }
  285. if len(task.receipts) != receiptLen {
  286. t.Errorf("receipt number mismatch: have %d, want %d", len(task.receipts), receiptLen)
  287. }
  288. if task.state.GetBalance(testUserAddress).Cmp(balance) != 0 {
  289. t.Errorf("account balance mismatch: have %d, want %d", task.state.GetBalance(testUserAddress), balance)
  290. }
  291. }
  292. w.newTaskHook = func(task *task) {
  293. if task.block.NumberU64() == 1 {
  294. checkEqual(t, task, taskIndex)
  295. taskIndex += 1
  296. taskCh <- struct{}{}
  297. }
  298. }
  299. w.fullTaskHook = func() {
  300. time.Sleep(100 * time.Millisecond)
  301. }
  302. // Ensure worker has finished initialization
  303. for {
  304. b := w.pendingBlock()
  305. if b != nil && b.NumberU64() == 1 {
  306. break
  307. }
  308. }
  309. w.start()
  310. for i := 0; i < 2; i += 1 {
  311. select {
  312. case <-taskCh:
  313. case <-time.NewTimer(2 * time.Second).C:
  314. t.Error("new task timeout")
  315. }
  316. }
  317. }
  318. func TestStreamUncleBlock(t *testing.T) {
  319. ethash := ethash.NewFaker()
  320. defer ethash.Close()
  321. w, b := newTestWorker(t, ethashChainConfig, ethash, rawdb.NewMemoryDatabase(), 1)
  322. defer w.close()
  323. var taskCh = make(chan struct{})
  324. taskIndex := 0
  325. w.newTaskHook = func(task *task) {
  326. if task.block.NumberU64() == 2 {
  327. if taskIndex == 2 {
  328. have := task.block.Header().UncleHash
  329. want := types.CalcUncleHash([]*types.Header{b.uncleBlock.Header()})
  330. if have != want {
  331. t.Errorf("uncle hash mismatch: have %s, want %s", have.Hex(), want.Hex())
  332. }
  333. }
  334. taskCh <- struct{}{}
  335. taskIndex += 1
  336. }
  337. }
  338. w.skipSealHook = func(task *task) bool {
  339. return true
  340. }
  341. w.fullTaskHook = func() {
  342. time.Sleep(100 * time.Millisecond)
  343. }
  344. // Ensure worker has finished initialization
  345. for {
  346. b := w.pendingBlock()
  347. if b != nil && b.NumberU64() == 2 {
  348. break
  349. }
  350. }
  351. w.start()
  352. // Ignore the first two works
  353. for i := 0; i < 2; i += 1 {
  354. select {
  355. case <-taskCh:
  356. case <-time.NewTimer(time.Second).C:
  357. t.Error("new task timeout")
  358. }
  359. }
  360. b.PostChainEvents([]interface{}{core.ChainSideEvent{Block: b.uncleBlock}})
  361. select {
  362. case <-taskCh:
  363. case <-time.NewTimer(time.Second).C:
  364. t.Error("new task timeout")
  365. }
  366. }
  367. func TestRegenerateMiningBlockEthash(t *testing.T) {
  368. testRegenerateMiningBlock(t, ethashChainConfig, ethash.NewFaker())
  369. }
  370. func TestRegenerateMiningBlockClique(t *testing.T) {
  371. testRegenerateMiningBlock(t, cliqueChainConfig, clique.New(cliqueChainConfig.Clique, rawdb.NewMemoryDatabase()))
  372. }
  373. func testRegenerateMiningBlock(t *testing.T, chainConfig *params.ChainConfig, engine consensus.Engine) {
  374. defer engine.Close()
  375. w, b := newTestWorker(t, chainConfig, engine, rawdb.NewMemoryDatabase(), 0)
  376. defer w.close()
  377. var taskCh = make(chan struct{})
  378. taskIndex := 0
  379. w.newTaskHook = func(task *task) {
  380. if task.block.NumberU64() == 1 {
  381. if taskIndex == 2 {
  382. receiptLen, balance := 2, big.NewInt(2000)
  383. if len(task.receipts) != receiptLen {
  384. t.Errorf("receipt number mismatch: have %d, want %d", len(task.receipts), receiptLen)
  385. }
  386. if task.state.GetBalance(testUserAddress).Cmp(balance) != 0 {
  387. t.Errorf("account balance mismatch: have %d, want %d", task.state.GetBalance(testUserAddress), balance)
  388. }
  389. }
  390. taskCh <- struct{}{}
  391. taskIndex += 1
  392. }
  393. }
  394. w.skipSealHook = func(task *task) bool {
  395. return true
  396. }
  397. w.fullTaskHook = func() {
  398. time.Sleep(100 * time.Millisecond)
  399. }
  400. // Ensure worker has finished initialization
  401. for {
  402. b := w.pendingBlock()
  403. if b != nil && b.NumberU64() == 1 {
  404. break
  405. }
  406. }
  407. w.start()
  408. // Ignore the first two works
  409. for i := 0; i < 2; i += 1 {
  410. select {
  411. case <-taskCh:
  412. case <-time.NewTimer(time.Second).C:
  413. t.Error("new task timeout")
  414. }
  415. }
  416. b.txPool.AddLocals(newTxs)
  417. time.Sleep(time.Second)
  418. select {
  419. case <-taskCh:
  420. case <-time.NewTimer(time.Second).C:
  421. t.Error("new task timeout")
  422. }
  423. }
  424. func TestAdjustIntervalEthash(t *testing.T) {
  425. testAdjustInterval(t, ethashChainConfig, ethash.NewFaker())
  426. }
  427. func TestAdjustIntervalClique(t *testing.T) {
  428. testAdjustInterval(t, cliqueChainConfig, clique.New(cliqueChainConfig.Clique, rawdb.NewMemoryDatabase()))
  429. }
  430. func testAdjustInterval(t *testing.T, chainConfig *params.ChainConfig, engine consensus.Engine) {
  431. defer engine.Close()
  432. w, _ := newTestWorker(t, chainConfig, engine, rawdb.NewMemoryDatabase(), 0)
  433. defer w.close()
  434. w.skipSealHook = func(task *task) bool {
  435. return true
  436. }
  437. w.fullTaskHook = func() {
  438. time.Sleep(100 * time.Millisecond)
  439. }
  440. var (
  441. progress = make(chan struct{}, 10)
  442. result = make([]float64, 0, 10)
  443. index = 0
  444. start = false
  445. )
  446. w.resubmitHook = func(minInterval time.Duration, recommitInterval time.Duration) {
  447. // Short circuit if interval checking hasn't started.
  448. if !start {
  449. return
  450. }
  451. var wantMinInterval, wantRecommitInterval time.Duration
  452. switch index {
  453. case 0:
  454. wantMinInterval, wantRecommitInterval = 3*time.Second, 3*time.Second
  455. case 1:
  456. origin := float64(3 * time.Second.Nanoseconds())
  457. estimate := origin*(1-intervalAdjustRatio) + intervalAdjustRatio*(origin/0.8+intervalAdjustBias)
  458. wantMinInterval, wantRecommitInterval = 3*time.Second, time.Duration(estimate)*time.Nanosecond
  459. case 2:
  460. estimate := result[index-1]
  461. min := float64(3 * time.Second.Nanoseconds())
  462. estimate = estimate*(1-intervalAdjustRatio) + intervalAdjustRatio*(min-intervalAdjustBias)
  463. wantMinInterval, wantRecommitInterval = 3*time.Second, time.Duration(estimate)*time.Nanosecond
  464. case 3:
  465. wantMinInterval, wantRecommitInterval = time.Second, time.Second
  466. }
  467. // Check interval
  468. if minInterval != wantMinInterval {
  469. t.Errorf("resubmit min interval mismatch: have %v, want %v ", minInterval, wantMinInterval)
  470. }
  471. if recommitInterval != wantRecommitInterval {
  472. t.Errorf("resubmit interval mismatch: have %v, want %v", recommitInterval, wantRecommitInterval)
  473. }
  474. result = append(result, float64(recommitInterval.Nanoseconds()))
  475. index += 1
  476. progress <- struct{}{}
  477. }
  478. // Ensure worker has finished initialization
  479. for {
  480. b := w.pendingBlock()
  481. if b != nil && b.NumberU64() == 1 {
  482. break
  483. }
  484. }
  485. w.start()
  486. time.Sleep(time.Second)
  487. start = true
  488. w.setRecommitInterval(3 * time.Second)
  489. select {
  490. case <-progress:
  491. case <-time.NewTimer(time.Second).C:
  492. t.Error("interval reset timeout")
  493. }
  494. w.resubmitAdjustCh <- &intervalAdjust{inc: true, ratio: 0.8}
  495. select {
  496. case <-progress:
  497. case <-time.NewTimer(time.Second).C:
  498. t.Error("interval reset timeout")
  499. }
  500. w.resubmitAdjustCh <- &intervalAdjust{inc: false}
  501. select {
  502. case <-progress:
  503. case <-time.NewTimer(time.Second).C:
  504. t.Error("interval reset timeout")
  505. }
  506. w.setRecommitInterval(500 * time.Millisecond)
  507. select {
  508. case <-progress:
  509. case <-time.NewTimer(time.Second).C:
  510. t.Error("interval reset timeout")
  511. }
  512. }