diff options
author | Sonic <sonic@dexon.org> | 2019-04-05 10:45:05 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2019-04-09 13:50:06 +0800 |
commit | 4e9059fc9d0e2949880359bdd4b1be21317050dd (patch) | |
tree | 606f9d2400108515a5203add3181fb041847c2d8 /build/testtool | |
parent | af1fd2506d151483244737ff6ffd5f2be9027c35 (diff) | |
download | dexon-4e9059fc9d0e2949880359bdd4b1be21317050dd.tar.gz dexon-4e9059fc9d0e2949880359bdd4b1be21317050dd.tar.zst dexon-4e9059fc9d0e2949880359bdd4b1be21317050dd.zip |
build: add end to end integration test for recovery mechanism (#336)
Diffstat (limited to 'build/testtool')
-rw-r--r-- | build/testtool/testtool.go | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/build/testtool/testtool.go b/build/testtool/testtool.go index 3f880b3bd..a801cfbb3 100644 --- a/build/testtool/testtool.go +++ b/build/testtool/testtool.go @@ -16,6 +16,7 @@ import ( "github.com/dexon-foundation/dexon" "github.com/dexon-foundation/dexon/accounts/abi" "github.com/dexon-foundation/dexon/cmd/zoo/monkey" + "github.com/dexon-foundation/dexon/core/types" "github.com/dexon-foundation/dexon/core/vm" "github.com/dexon-foundation/dexon/crypto" "github.com/dexon-foundation/dexon/ethclient" @@ -34,6 +35,8 @@ func main() { doVerifyGovMPK(os.Args[2:]) case "monkeyTest": doMonkeyTest(os.Args[2:]) + case "waitForRecovery": + doWaitForRecovery(os.Args[2:]) case "upload": doUpload(os.Args[2:]) } @@ -206,3 +209,58 @@ func doMonkeyTest(args []string) { } } } + +func doWaitForRecovery(args []string) { + if len(args) < 2 { + log.Fatal("arg length is not enough") + } + + client, err := ethclient.Dial(args[0]) + if err != nil { + log.Fatalf("new ethclient fail: %v", err) + } + + lastBlock, err := client.BlockByNumber(context.Background(), nil) + if err != nil { + log.Fatalf("get last block fail %v", err) + } + t, err := strconv.ParseInt(args[1], 10, 64) + if err != nil { + log.Fatalf("timeout args invalid, %s", args[1]) + } + + sleep := time.Duration(t) * time.Second + + ctx, cancel := context.WithCancel(context.Background()) + + go func() { + for ctx.Err() == nil { + select { + case <-time.After(1 * time.Minute): + log.Printf("tick") + case <-ctx.Done(): + return + } + } + }() + + log.Printf("Sleep %s", sleep) + time.Sleep(sleep) + cancel() + + // Check block height is increasing 5 time for safe. + var block *types.Block + for i := 0; i < 5; i++ { + block, err = client.BlockByNumber(context.Background(), nil) + if err != nil { + log.Fatalf("get current block fail, err=%v, i=%d", err, i) + } + if block.NumberU64() <= lastBlock.NumberU64() { + log.Fatalf("recovery fail, last=%d, current=%d", + lastBlock.NumberU64(), block.NumberU64()) + } + log.Printf("last=%d, current=%d, ok, sleep a while", lastBlock.NumberU64(), block.NumberU64()) + lastBlock = block + time.Sleep(2 * time.Second) + } +} |