worker_test.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  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. // Aarch64 unit tests are running in a VM on travis, they must
  301. // be given more time to execute.
  302. time.Sleep(time.Second)
  303. }
  304. // Ensure worker has finished initialization
  305. for {
  306. b := w.pendingBlock()
  307. if b != nil && b.NumberU64() == 1 {
  308. break
  309. }
  310. }
  311. w.start()
  312. for i := 0; i < 2; i += 1 {
  313. select {
  314. case <-taskCh:
  315. case <-time.NewTimer(30 * time.Second).C:
  316. t.Error("new task timeout")
  317. }
  318. }
  319. }
  320. func TestStreamUncleBlock(t *testing.T) {
  321. ethash := ethash.NewFaker()
  322. defer ethash.Close()
  323. w, b := newTestWorker(t, ethashChainConfig, ethash, rawdb.NewMemoryDatabase(), 1)
  324. defer w.close()
  325. var taskCh = make(chan struct{})
  326. taskIndex := 0
  327. w.newTaskHook = func(task *task) {
  328. if task.block.NumberU64() == 2 {
  329. if taskIndex == 2 {
  330. have := task.block.Header().UncleHash
  331. want := types.CalcUncleHash([]*types.Header{b.uncleBlock.Header()})
  332. if have != want {
  333. t.Errorf("uncle hash mismatch: have %s, want %s", have.Hex(), want.Hex())
  334. }
  335. }
  336. taskCh <- struct{}{}
  337. taskIndex += 1
  338. }
  339. }
  340. w.skipSealHook = func(task *task) bool {
  341. return true
  342. }
  343. w.fullTaskHook = func() {
  344. time.Sleep(100 * time.Millisecond)
  345. }
  346. // Ensure worker has finished initialization
  347. for {
  348. b := w.pendingBlock()
  349. if b != nil && b.NumberU64() == 2 {
  350. break
  351. }
  352. }
  353. w.start()
  354. // Ignore the first two works
  355. for i := 0; i < 2; i += 1 {
  356. select {
  357. case <-taskCh:
  358. case <-time.NewTimer(time.Second).C:
  359. t.Error("new task timeout")
  360. }
  361. }
  362. b.PostChainEvents([]interface{}{core.ChainSideEvent{Block: b.uncleBlock}})
  363. select {
  364. case <-taskCh:
  365. case <-time.NewTimer(time.Second).C:
  366. t.Error("new task timeout")
  367. }
  368. }
  369. func TestRegenerateMiningBlockEthash(t *testing.T) {
  370. testRegenerateMiningBlock(t, ethashChainConfig, ethash.NewFaker())
  371. }
  372. func TestRegenerateMiningBlockClique(t *testing.T) {
  373. testRegenerateMiningBlock(t, cliqueChainConfig, clique.New(cliqueChainConfig.Clique, rawdb.NewMemoryDatabase()))
  374. }
  375. func testRegenerateMiningBlock(t *testing.T, chainConfig *params.ChainConfig, engine consensus.Engine) {
  376. defer engine.Close()
  377. w, b := newTestWorker(t, chainConfig, engine, rawdb.NewMemoryDatabase(), 0)
  378. defer w.close()
  379. var taskCh = make(chan struct{})
  380. taskIndex := 0
  381. w.newTaskHook = func(task *task) {
  382. if task.block.NumberU64() == 1 {
  383. if taskIndex == 2 {
  384. receiptLen, balance := 2, big.NewInt(2000)
  385. if len(task.receipts) != receiptLen {
  386. t.Errorf("receipt number mismatch: have %d, want %d", len(task.receipts), receiptLen)
  387. }
  388. if task.state.GetBalance(testUserAddress).Cmp(balance) != 0 {
  389. t.Errorf("account balance mismatch: have %d, want %d", task.state.GetBalance(testUserAddress), balance)
  390. }
  391. }
  392. taskCh <- struct{}{}
  393. taskIndex += 1
  394. }
  395. }
  396. w.skipSealHook = func(task *task) bool {
  397. return true
  398. }
  399. w.fullTaskHook = func() {
  400. time.Sleep(100 * time.Millisecond)
  401. }
  402. // Ensure worker has finished initialization
  403. for {
  404. b := w.pendingBlock()
  405. if b != nil && b.NumberU64() == 1 {
  406. break
  407. }
  408. }
  409. w.start()
  410. // Ignore the first two works
  411. for i := 0; i < 2; i += 1 {
  412. select {
  413. case <-taskCh:
  414. case <-time.NewTimer(time.Second).C:
  415. t.Error("new task timeout")
  416. }
  417. }
  418. b.txPool.AddLocals(newTxs)
  419. time.Sleep(time.Second)
  420. select {
  421. case <-taskCh:
  422. case <-time.NewTimer(time.Second).C:
  423. t.Error("new task timeout")
  424. }
  425. }
  426. func TestAdjustIntervalEthash(t *testing.T) {
  427. testAdjustInterval(t, ethashChainConfig, ethash.NewFaker())
  428. }
  429. func TestAdjustIntervalClique(t *testing.T) {
  430. testAdjustInterval(t, cliqueChainConfig, clique.New(cliqueChainConfig.Clique, rawdb.NewMemoryDatabase()))
  431. }
  432. func testAdjustInterval(t *testing.T, chainConfig *params.ChainConfig, engine consensus.Engine) {
  433. defer engine.Close()
  434. w, _ := newTestWorker(t, chainConfig, engine, rawdb.NewMemoryDatabase(), 0)
  435. defer w.close()
  436. w.skipSealHook = func(task *task) bool {
  437. return true
  438. }
  439. w.fullTaskHook = func() {
  440. time.Sleep(100 * time.Millisecond)
  441. }
  442. var (
  443. progress = make(chan struct{}, 10)
  444. result = make([]float64, 0, 10)
  445. index = 0
  446. start = false
  447. )
  448. w.resubmitHook = func(minInterval time.Duration, recommitInterval time.Duration) {
  449. // Short circuit if interval checking hasn't started.
  450. if !start {
  451. return
  452. }
  453. var wantMinInterval, wantRecommitInterval time.Duration
  454. switch index {
  455. case 0:
  456. wantMinInterval, wantRecommitInterval = 3*time.Second, 3*time.Second
  457. case 1:
  458. origin := float64(3 * time.Second.Nanoseconds())
  459. estimate := origin*(1-intervalAdjustRatio) + intervalAdjustRatio*(origin/0.8+intervalAdjustBias)
  460. wantMinInterval, wantRecommitInterval = 3*time.Second, time.Duration(estimate)*time.Nanosecond
  461. case 2:
  462. estimate := result[index-1]
  463. min := float64(3 * time.Second.Nanoseconds())
  464. estimate = estimate*(1-intervalAdjustRatio) + intervalAdjustRatio*(min-intervalAdjustBias)
  465. wantMinInterval, wantRecommitInterval = 3*time.Second, time.Duration(estimate)*time.Nanosecond
  466. case 3:
  467. wantMinInterval, wantRecommitInterval = time.Second, time.Second
  468. }
  469. // Check interval
  470. if minInterval != wantMinInterval {
  471. t.Errorf("resubmit min interval mismatch: have %v, want %v ", minInterval, wantMinInterval)
  472. }
  473. if recommitInterval != wantRecommitInterval {
  474. t.Errorf("resubmit interval mismatch: have %v, want %v", recommitInterval, wantRecommitInterval)
  475. }
  476. result = append(result, float64(recommitInterval.Nanoseconds()))
  477. index += 1
  478. progress <- struct{}{}
  479. }
  480. // Ensure worker has finished initialization
  481. for {
  482. b := w.pendingBlock()
  483. if b != nil && b.NumberU64() == 1 {
  484. break
  485. }
  486. }
  487. w.start()
  488. time.Sleep(time.Second)
  489. start = true
  490. w.setRecommitInterval(3 * time.Second)
  491. select {
  492. case <-progress:
  493. case <-time.NewTimer(time.Second).C:
  494. t.Error("interval reset timeout")
  495. }
  496. w.resubmitAdjustCh <- &intervalAdjust{inc: true, ratio: 0.8}
  497. select {
  498. case <-progress:
  499. case <-time.NewTimer(time.Second).C:
  500. t.Error("interval reset timeout")
  501. }
  502. w.resubmitAdjustCh <- &intervalAdjust{inc: false}
  503. select {
  504. case <-progress:
  505. case <-time.NewTimer(time.Second).C:
  506. t.Error("interval reset timeout")
  507. }
  508. w.setRecommitInterval(500 * time.Millisecond)
  509. select {
  510. case <-progress:
  511. case <-time.NewTimer(time.Second).C:
  512. t.Error("interval reset timeout")
  513. }
  514. }