-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(
btcdctrl
): handle & test for flaky edge-cases
1. killing a process then waiting for it can return an error depending on state, instead just exit the loop. 2. websockets hang indefinitely every 20 tests or so, use HTTP POST instead. 3. handle the RPC/P2P message being the last line in the log.
- Loading branch information
Showing
3 changed files
with
96 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,37 @@ | ||
package btcdctrl_test | ||
package btcdctrl | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/btcsuite/btcd/btcdctrl" | ||
"testing" | ||
) | ||
|
||
func ExampleController() { | ||
// Create a temporary directory for the wallet data. | ||
tmp, err := os.MkdirTemp("", "") | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
// Create a new test-oriented configration. | ||
cfg, err := btcdctrl.NewTestConfig(tmp) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
// Create a new controller. | ||
c := btcdctrl.New(&btcdctrl.ControllerConfig{ | ||
Stderr: os.Stderr, | ||
Stdout: os.Stdout, | ||
|
||
Config: cfg, | ||
}) | ||
|
||
// Start btcd. | ||
err = c.Start() | ||
if err != nil { | ||
panic(err) | ||
func TestFail(t *testing.T) { | ||
for i := 0; i < 100; i++ { | ||
cfg, err := NewTestConfig(t.TempDir()) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
cfg.DebugLevel = "trace" | ||
|
||
// Create a new controller. | ||
c := New(&ControllerConfig{ | ||
Stderr: os.Stderr, | ||
Stdout: os.Stdout, | ||
|
||
Config: cfg, | ||
}) | ||
|
||
// Start btcd. | ||
err = c.Start() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
// Stop btcd. | ||
err = c.Stop() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
} | ||
|
||
// Stop btcd on exit. | ||
defer c.Stop() | ||
|
||
// Enable generation. | ||
err = c.SetGenerate(true, 0) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
// Generate 100 blocks. | ||
_, err = c.Generate(100) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
// Query info. | ||
info, err := c.GetInfo() | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
fmt.Println(info.Blocks) | ||
// Output: 100 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package btcdctrl_test | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/btcsuite/btcd/btcdctrl" | ||
) | ||
|
||
func ExampleController() { | ||
// Create a temporary directory for the wallet data. | ||
tmp, err := os.MkdirTemp("", "") | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
// Create a new test-oriented configration. | ||
cfg, err := btcdctrl.NewTestConfig(tmp) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
// Create a new controller. | ||
c := btcdctrl.New(&btcdctrl.ControllerConfig{ | ||
Config: cfg, | ||
}) | ||
|
||
// Start btcd. | ||
err = c.Start() | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
// Stop btcd on exit. | ||
defer c.Stop() | ||
|
||
// Enable generation. | ||
err = c.SetGenerate(true, 0) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
// Generate 100 blocks. | ||
_, err = c.Generate(100) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
// Query info. | ||
info, err := c.GetInfo() | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
fmt.Println(info.Blocks) | ||
// Output: 100 | ||
} |