Wait for backend startup in integration test

pull/174/head
Martin Boehm 2019-05-06 22:34:07 +02:00
parent 5322cea4a5
commit 2d3e7c9612
2 changed files with 18 additions and 10 deletions

View File

@ -63,7 +63,7 @@
} }
}, },
"meta": { "meta": {
"package_maintainer": "Martin Boehm", "package_maintainer": "Martin Bohm",
"package_maintainer_email": "martin.bohm@satoshilabs.com" "package_maintainer_email": "martin.bohm@satoshilabs.com"
} }
} }

View File

@ -19,6 +19,7 @@ import (
"sort" "sort"
"strings" "strings"
"testing" "testing"
"time"
"github.com/martinboehm/btcutil/chaincfg" "github.com/martinboehm/btcutil/chaincfg"
) )
@ -81,7 +82,7 @@ func runTests(t *testing.T, coin string, cfg map[string]json.RawMessage) {
if err == notConnectedError { if err == notConnectedError {
t.Fatal(err) t.Fatal(err)
} }
t.Fatalf("Cannot make blockchain config: %s", err) t.Fatalf("Cannot init blockchain: %s", err)
} }
for test, c := range cfg { for test, c := range cfg {
@ -153,7 +154,7 @@ func initBlockChain(coinName string, cfg json.RawMessage) (bchain.BlockChain, bc
return nil, nil, fmt.Errorf("Factory function not found") return nil, nil, fmt.Errorf("Factory function not found")
} }
cli, err := factory(cfg, func(_ bchain.NotificationType) {}) chain, err := factory(cfg, func(_ bchain.NotificationType) {})
if err != nil { if err != nil {
if isNetError(err) { if isNetError(err) {
return nil, nil, notConnectedError return nil, nil, notConnectedError
@ -161,25 +162,32 @@ func initBlockChain(coinName string, cfg json.RawMessage) (bchain.BlockChain, bc
return nil, nil, fmt.Errorf("Factory function failed: %s", err) return nil, nil, fmt.Errorf("Factory function failed: %s", err)
} }
err = cli.Initialize() for i := 0; ; i++ {
if err != nil { err = chain.Initialize()
if err == nil {
break
}
if isNetError(err) { if isNetError(err) {
return nil, nil, notConnectedError return nil, nil, notConnectedError
} }
return nil, nil, fmt.Errorf("BlockChain initialization failed: %s", err) // wait max 5 minutes for backend to startup
if i > 5*60 {
return nil, nil, fmt.Errorf("BlockChain initialization failed: %s", err)
}
time.Sleep(time.Millisecond * 1000)
} }
mempool, err := cli.CreateMempool(cli) mempool, err := chain.CreateMempool(chain)
if err != nil { if err != nil {
return nil, nil, fmt.Errorf("Mempool creation failed: %s", err) return nil, nil, fmt.Errorf("Mempool creation failed: %s", err)
} }
err = cli.InitializeMempool(nil, nil) err = chain.InitializeMempool(nil, nil)
if err != nil { if err != nil {
return nil, nil, fmt.Errorf("Mempool initialization failed: %s", err) return nil, nil, fmt.Errorf("Mempool initialization failed: %s", err)
} }
return cli, mempool, nil return chain, mempool, nil
} }
func isNetError(err error) bool { func isNetError(err error) bool {