func TestRpcServer(t *testing.T) { var currentTestNum int defer func() { // If one of the integration tests caused a panic within the main // goroutine, then tear down all the harnesses in order to avoid // any leaked btcd processes. if r := recover(); r != nil { fmt.Println("recovering from test panic: ", r) if err := rpctest.TearDownAll(); err != nil { fmt.Println("unable to tear down all harnesses: ", err) } t.Fatalf("test #%v panicked: %s", currentTestNum, debug.Stack()) } }() for _, testCase := range rpcTestCases { testCase(primaryHarness, t) currentTestNum++ } }
func TestMain(m *testing.M) { var err error // In order to properly test scenarios on as if we were on mainnet, // ensure that non-standard transactions aren't accepted into the // mempool or relayed. btcdCfg := []string{"--rejectnonstd"} primaryHarness, err = rpctest.New(&chaincfg.SimNetParams, nil, btcdCfg) if err != nil { fmt.Println("unable to create primary harness: ", err) os.Exit(1) } // Initialize the primary mining node with a chain of length 125, // providing 25 mature coinbases to allow spending from for testing // purposes. if err := primaryHarness.SetUp(true, 25); err != nil { fmt.Println("unable to setup test chain: ", err) // Even though the harness was not fully setup, it still needs // to be torn down to ensure all resources such as temp // directories are cleaned up. The error is intentionally // ignored since this is already an error path and nothing else // could be done about it anyways. _ = primaryHarness.TearDown() os.Exit(1) } exitCode := m.Run() // Clean up any active harnesses that are still currently running.This // includes removing all temporary directories, and shutting down any // created processes. if err := rpctest.TearDownAll(); err != nil { fmt.Println("unable to tear down all harnesses: ", err) os.Exit(1) } os.Exit(exitCode) }