mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
WaitSynced but still not working
This commit is contained in:
parent
3b043ddbef
commit
46c49a4236
1 changed files with 16 additions and 3 deletions
|
|
@ -72,6 +72,16 @@ func (g *gethrpc) addPeer(enode string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *gethrpc) waitSynced() {
|
func (g *gethrpc) waitSynced() {
|
||||||
|
// Check if it's synced now
|
||||||
|
var result interface{}
|
||||||
|
g.callRPC(&result, "eth_syncing")
|
||||||
|
syncing, ok := result.(bool)
|
||||||
|
if ok && !syncing {
|
||||||
|
g.test.Logf("%v already synced", g.name)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actually wait, subscribe to the event
|
||||||
ch := make(chan interface{})
|
ch := make(chan interface{})
|
||||||
sub, err := g.rpc.Subscribe(context.Background(), "eth", ch, "syncing")
|
sub, err := g.rpc.Subscribe(context.Background(), "eth", ch, "syncing")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -79,10 +89,11 @@ func (g *gethrpc) waitSynced() {
|
||||||
}
|
}
|
||||||
defer sub.Unsubscribe()
|
defer sub.Unsubscribe()
|
||||||
g.test.Log("subscribed")
|
g.test.Log("subscribed")
|
||||||
timeout := time.After(40 * time.Second)
|
timeout := time.After(4 * time.Second)
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case ev := <-ch:
|
case ev := <-ch:
|
||||||
|
g.test.Log("'syncing' event", ev)
|
||||||
syncing, ok := ev.(bool)
|
syncing, ok := ev.(bool)
|
||||||
if ok && !syncing {
|
if ok && !syncing {
|
||||||
return
|
return
|
||||||
|
|
@ -90,8 +101,10 @@ func (g *gethrpc) waitSynced() {
|
||||||
g.test.Log("Other 'syncing' event", ev)
|
g.test.Log("Other 'syncing' event", ev)
|
||||||
case err := <-sub.Err():
|
case err := <-sub.Err():
|
||||||
g.test.Fatalf("%v notification: %v", g.name, err)
|
g.test.Fatalf("%v notification: %v", g.name, err)
|
||||||
|
return
|
||||||
case <-timeout:
|
case <-timeout:
|
||||||
g.test.Fatalf("%v timeout syncing: %v", g.name, err)
|
g.test.Fatalf("%v timeout syncing", g.name)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -144,7 +157,7 @@ func TestPriorityClient(t *testing.T) {
|
||||||
nodeInfo := make(map[string]interface{})
|
nodeInfo := make(map[string]interface{})
|
||||||
server.callRPC(&nodeInfo, "admin_nodeInfo")
|
server.callRPC(&nodeInfo, "admin_nodeInfo")
|
||||||
enode := nodeInfo["enode"].(string)
|
enode := nodeInfo["enode"].(string)
|
||||||
//server.waitSynced()
|
server.waitSynced()
|
||||||
|
|
||||||
client := startClient(t)
|
client := startClient(t)
|
||||||
defer client.killAndWait()
|
defer client.killAndWait()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue