Commit d79d5f74 authored by David Vorick's avatar David Vorick

convert Close to panicClose, parallelize some longer tests

parent 25e04bd9
......@@ -2,7 +2,7 @@ package api
// ecosystem_helpers_test.go has a bunch of helper functions to make setting up
// large ecosystem tests easier.
//
// List of helper functions:
// addStorageToAllHosts // adds a storage folder to every host
// announceAllHosts // announce all hosts to the network (and mine a block)
......@@ -11,6 +11,14 @@ package api
// synchronizationCheck // checks that all server testers have the same recent block
// waitForBlock // block until the provided block is the most recent block for all server testers
import (
"errors"
"net/url"
"time"
"github.com/NebulousLabs/Sia/types"
)
// addStorageToAllHosts adds a storage folder with a bunch of storage to each
// host.
func addStorageToAllHosts(sts []*serverTester) error {
......
......@@ -8,8 +8,6 @@ package api
// exclusively through the API.
import (
"errors"
"net/url"
"testing"
"time"
......@@ -27,6 +25,7 @@ func TestHostPoorConnectivity(t *testing.T) {
if testing.Short() {
t.SkipNow()
}
t.Parallel()
// Create the various nodes that will be forming the simulated ecosystem of
// this test.
......
......@@ -16,7 +16,7 @@ func TestIntegrationExplorerGET(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer st.server.Close()
defer st.server.panicClose()
var eg ExplorerGET
err = st.getAPI("/explorer", &eg)
......@@ -41,7 +41,7 @@ func TestIntegrationExplorerBlockGET(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer st.server.Close()
defer st.server.panicClose()
var ebg ExplorerBlockGET
err = st.getAPI("/explorer/blocks/0", &ebg)
......@@ -66,7 +66,7 @@ func TestIntegrationExplorerHashGet(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer st.server.Close()
defer st.server.panicClose()
var ehg ExplorerHashGET
gb := types.GenesisBlock
......
......@@ -18,7 +18,7 @@ func TestGatewayStatus(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer st.server.Close()
defer st.server.panicClose()
var info GatewayGET
st.getAPI("/gateway", &info)
......@@ -38,12 +38,18 @@ func TestGatewayPeerConnect(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer st.server.Close()
defer st.server.panicClose()
peer, err := gateway.New("localhost:0", false, build.TempDir("api", t.Name(), "gateway"))
peer, err := gateway.New("localhost:0", false, build.TempDir("api", t.Name()+"2", "gateway"))
if err != nil {
t.Fatal(err)
}
defer func() {
err := peer.Close()
if err != nil {
panic(err)
}
}()
err = st.stdPostAPI("/gateway/connect/"+string(peer.Address()), nil)
if err != nil {
t.Fatal(err)
......@@ -70,12 +76,18 @@ func TestGatewayPeerDisconnect(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer st.server.Close()
defer st.server.panicClose()
peer, err := gateway.New("localhost:0", false, build.TempDir("api", t.Name()+"2", "gateway"))
if err != nil {
t.Fatal(err)
}
defer func() {
err := peer.Close()
if err != nil {
panic(err)
}
}()
err = st.stdPostAPI("/gateway/connect/"+string(peer.Address()), nil)
if err != nil {
t.Fatal(err)
......
......@@ -58,7 +58,7 @@ func TestWorkingStatus(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer st.server.Close()
defer st.server.panicClose()
// announce a host, create an allowance, upload some data.
if err := st.announceHost(); err != nil {
......@@ -127,7 +127,7 @@ func TestConnectabilityStatus(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer st.server.Close()
defer st.server.panicClose()
if err := st.announceHost(); err != nil {
t.Fatal(err)
......@@ -155,7 +155,7 @@ func TestStorageHandler(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer st.server.Close()
defer st.server.panicClose()
// Announce the host and start accepting contracts.
if err := st.announceHost(); err != nil {
......@@ -227,7 +227,7 @@ func TestAddFolderNoPath(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer st.server.Close()
defer st.server.panicClose()
// Try adding a storage folder without setting "path" in the API call.
addValues := url.Values{}
......@@ -256,7 +256,7 @@ func TestAddFolderNoSize(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer st.server.Close()
defer st.server.panicClose()
// Try adding a storage folder without setting "size" in the API call.
addValues := url.Values{}
......@@ -278,7 +278,7 @@ func TestAddSameFolderTwice(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer st.server.Close()
defer st.server.panicClose()
// Make the call to add a storage folder twice.
addValues := url.Values{}
......@@ -305,7 +305,7 @@ func TestResizeEmptyStorageFolder(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer st.server.Close()
defer st.server.panicClose()
// Announce the host and start accepting contracts.
if err := st.announceHost(); err != nil {
......@@ -387,7 +387,7 @@ func TestResizeNonemptyStorageFolder(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer st.server.Close()
defer st.server.panicClose()
// Announce the host and start accepting contracts.
if err := st.announceHost(); err != nil {
......@@ -500,7 +500,7 @@ func TestResizeNonexistentFolder(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer st.server.Close()
defer st.server.panicClose()
// No folder has been created yet at st.dir, so using it as the path for
// the resize call should trigger an error.
......@@ -524,7 +524,7 @@ func TestResizeFolderNoPath(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer st.server.Close()
defer st.server.panicClose()
// The call to resize should fail if no path has been provided.
resizeValues := url.Values{}
......@@ -546,7 +546,7 @@ func TestRemoveEmptyStorageFolder(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer st.server.Close()
defer st.server.panicClose()
// Set up a storage folder for the host.
if err := st.setHostStorage(); err != nil {
......@@ -572,7 +572,7 @@ func TestRemoveStorageFolderError(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer st.server.Close()
defer st.server.panicClose()
// Set up a storage folder for the host.
if err := st.setHostStorage(); err != nil {
......@@ -607,7 +607,7 @@ func TestRemoveStorageFolderForced(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer st.server.Close()
defer st.server.panicClose()
// Announce the host.
if err := st.announceHost(); err != nil {
......@@ -678,7 +678,7 @@ func TestDeleteSector(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer st.server.Close()
defer st.server.panicClose()
// Set up the host for forming contracts.
if err := st.announceHost(); err != nil {
......@@ -746,7 +746,7 @@ func TestDeleteNonexistentSector(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer st.server.Close()
defer st.server.panicClose()
// These calls to delete imaginary sectors should fail for a few reasons:
// - the given sector root strings are invalid
......
......@@ -31,7 +31,7 @@ func TestHostDBHostsActiveHandler(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer st.server.Close()
defer st.server.panicClose()
// Try the call with numhosts unset, and set to -1, 0, and 1.
var ah HostdbActiveGET
......@@ -120,7 +120,7 @@ func TestHostDBHostsAllHandler(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer st.server.Close()
defer st.server.panicClose()
// Try the call before any hosts have been declared.
var ah HostdbAllGET
......@@ -151,7 +151,7 @@ func TestHostDBHostsHandler(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer st.server.Close()
defer st.server.panicClose()
// Announce the host and then get the list of hosts.
var ah HostdbActiveGET
......@@ -325,6 +325,7 @@ func TestHostDBScanOnlineOffline(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer st.panicClose()
stHost, err := blankServerTester(t.Name() + "-Host")
if err != nil {
t.Fatal(err)
......@@ -393,6 +394,7 @@ func TestHostDBScanOnlineOffline(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer stHost.panicClose()
sts[1] = stHost
err = fullyConnectNodes(sts)
if err != nil {
......@@ -425,6 +427,7 @@ func TestHostDBAndRenterDownloadDynamicIPs(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer st.panicClose()
stHost, err := blankServerTester(t.Name() + "-Host")
if err != nil {
t.Fatal(err)
......@@ -546,6 +549,7 @@ func TestHostDBAndRenterDownloadDynamicIPs(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer stHost.panicClose()
sts[1] = stHost
err = fullyConnectNodes(sts)
if err != nil {
......@@ -643,6 +647,7 @@ func TestHostDBAndRenterUploadDynamicIPs(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer st.panicClose()
stHost, err := blankServerTester(t.Name() + "-Host")
if err != nil {
t.Fatal(err)
......@@ -745,6 +750,7 @@ func TestHostDBAndRenterUploadDynamicIPs(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer stHost.panicClose()
sts[1] = stHost
err = fullyConnectNodes(sts)
if err != nil {
......@@ -892,6 +898,7 @@ func TestHostDBAndRenterFormDynamicIPs(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer st.panicClose()
stHost, err := blankServerTester(t.Name() + "-Host")
if err != nil {
t.Fatal(err)
......@@ -960,6 +967,7 @@ func TestHostDBAndRenterFormDynamicIPs(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer stHost.panicClose()
sts[1] = stHost
err = fullyConnectNodes(sts)
if err != nil {
......@@ -1096,6 +1104,7 @@ func TestHostDBAndRenterRenewDynamicIPs(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer st.panicClose()
stHost, err := blankServerTester(t.Name() + "-Host")
if err != nil {
t.Fatal(err)
......@@ -1210,6 +1219,7 @@ func TestHostDBAndRenterRenewDynamicIPs(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer stHost.panicClose()
sts[1] = stHost
err = fullyConnectNodes(sts)
if err != nil {
......
......@@ -19,7 +19,7 @@ func TestMinerGET(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer st.server.Close()
defer st.server.panicClose()
// Get the api returned fields of the miner.
var mg MinerGET
......@@ -55,7 +55,7 @@ func TestMinerStartStop(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer st.server.Close()
defer st.server.panicClose()
// Start the cpu miner, give time for the first hashrate readings to
// appear.
......@@ -109,7 +109,7 @@ func TestMinerHeader(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer st.server.Close()
defer st.server.panicClose()
startingHeight := st.cs.Height()
// Get a header that can be used for mining.
......
......@@ -38,7 +38,7 @@ func TestRenterDownloadError(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer st.server.Close()
defer st.server.panicClose()
// Announce the host and start accepting contracts.
err = st.announceHost()
......@@ -112,7 +112,7 @@ func TestRenterAsyncDownloadError(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer st.server.Close()
defer st.server.panicClose()
// Announce the host and start accepting contracts.
err = st.announceHost()
......@@ -187,7 +187,7 @@ func TestRenterAsyncDownload(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer st.server.Close()
defer st.server.panicClose()
// Announce the host and start accepting contracts.
err = st.announceHost()
......@@ -291,7 +291,7 @@ func TestRenterPaths(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer st.server.Close()
defer st.server.panicClose()
// Announce the host.
err = st.announceHost()
......@@ -336,7 +336,7 @@ func TestRenterConflicts(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer st.server.Close()
defer st.server.panicClose()
// Announce the host.
err = st.announceHost()
......@@ -397,7 +397,7 @@ func TestRenterHandlerContracts(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer st.server.Close()
defer st.server.panicClose()
// Anounce the host and start accepting contracts.
if err := st.announceHost(); err != nil {
......@@ -461,7 +461,7 @@ func TestRenterHandlerGetAndPost(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer st.server.Close()
defer st.server.panicClose()
// Anounce the host and start accepting contracts.
if err := st.announceHost(); err != nil {
......@@ -558,7 +558,7 @@ func TestRenterLoadNonexistent(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer st.server.Close()
defer st.server.panicClose()
// Anounce the host and start accepting contracts.
if err := st.announceHost(); err != nil {
......@@ -616,7 +616,7 @@ func TestRenterHandlerRename(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer st.server.Close()
defer st.server.panicClose()
// Anounce the host and start accepting contracts.
if err := st.announceHost(); err != nil {
......@@ -714,7 +714,7 @@ func TestRenterHandlerDelete(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer st.server.Close()
defer st.server.panicClose()
// Anounce the host and start accepting contracts.
if err := st.announceHost(); err != nil {
......@@ -779,7 +779,7 @@ func TestRenterRelativePathErrorUpload(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer st.server.Close()
defer st.server.panicClose()
// Anounce the host and start accepting contracts.
if err := st.announceHost(); err != nil {
......@@ -840,7 +840,7 @@ func TestRenterRelativePathErrorDownload(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer st.server.Close()
defer st.server.panicClose()
// Anounce the host and start accepting contracts.
if err := st.announceHost(); err != nil {
......@@ -920,7 +920,7 @@ func TestRenterPricesHandler(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer st.server.Close()
defer st.server.panicClose()
// Announce the host and then get the calculated prices for when there is a
// single host.
......@@ -937,10 +937,12 @@ func TestRenterPricesHandler(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer stHost1.panicClose()
stHost2, err := blankServerTester(t.Name() + " - Host 2")
if err != nil {
t.Fatal(err)
}
defer stHost2.panicClose()
// Connect all the nodes and announce all of the hosts.
sts := []*serverTester{st, stHost1, stHost2}
......@@ -992,7 +994,7 @@ func TestRenterPricesHandlerCheap(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer st.server.Close()
defer st.server.panicClose()
// Announce the host and then get the calculated prices for when there is a
// single host.
......@@ -1009,10 +1011,12 @@ func TestRenterPricesHandlerCheap(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer stHost1.panicClose()
stHost2, err := blankServerTester(t.Name() + " - Host 2")
if err != nil {
t.Fatal(err)
}
defer stHost2.panicClose()
var hg HostGET
err = st.getAPI("/host", &hg)
......@@ -1093,7 +1097,7 @@ func TestRenterPricesHandlerIgnorePricey(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer st.server.Close()
defer st.server.panicClose()
// Announce the host and then get the calculated prices for when there is a
// single host.
......@@ -1110,22 +1114,27 @@ func TestRenterPricesHandlerIgnorePricey(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer stHost1.panicClose()
stHost2, err := blankServerTester(t.Name() + " - Host 2")
if err != nil {
t.Fatal(err)
}
defer stHost2.panicClose()
stHost3, err := blankServerTester(t.Name() + " - Host 3")
if err != nil {
t.Fatal(err)
}
defer stHost3.panicClose()
stHost4, err := blankServerTester(t.Name() + " - Host 4")
if err != nil {
t.Fatal(err)
}
defer stHost4.panicClose()
stHost5, err := blankServerTester(t.Name() + " - Host 5")
if err != nil {
t.Fatal(err)
}
defer stHost5.panicClose()
// Set host 5 to be cheaper than the rest by a substantial amount. This
// should result in a reduction for the price estimation.
......@@ -1193,7 +1202,7 @@ func TestRenterPricesHandlerPricey(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer st.server.Close()
defer st.server.panicClose()
// Announce the host and then get the calculated prices for when there is a
// single host.
......
......@@ -24,11 +24,12 @@ func TestHostAndRentVanilla(t *testing.T) {
if testing.Short() {
t.SkipNow()
}
t.Parallel()
st, err := createServerTester(t.Name())
if err != nil {
t.Fatal(err)
}
defer st.server.Close()
defer st.server.panicClose()
// Announce the host and start accepting contracts.
err = st.announceHost()
......@@ -213,21 +214,22 @@ func TestHostAndRentMultiHost(t *testing.T) {
if testing.Short() {
t.SkipNow()
}
t.Parallel()
st, err := createServerTester(t.Name())
if err != nil {
t.Fatal(err)
}
defer st.server.Close()
defer st.server.panicClose()
stH1, err := blankServerTester(t.Name() + " - Host 2")
if err != nil {
t.Fatal(err)
}
defer stH1.server.Close()
defer stH1.server.panicClose()
stH2, err := blankServerTester(t.Name() + " - Host 3")
if err != nil {
t.Fatal(err)
}
defer stH2.server.Close()
defer stH2.server.panicClose()
testGroup := []*serverTester{st, stH1, stH2}
// Connect the testers to eachother so that they are all on the same
......@@ -328,26 +330,27 @@ func TestHostAndRentManyFiles(t *testing.T) {
if testing.Short() {
t.SkipNow()
}
t.Parallel()
st, err := createServerTester(t.Name())
if err != nil {
t.Fatal(err)
}
defer st.server.Close()
defer st.server.panicClose()
stH1, err := blankServerTester(t.Name() + " - Host 2")
if err != nil {
t.Fatal(err)
}
defer stH1.server.Close()
defer stH1.server.panicClose()
stH2, err := blankServerTester(t.Name() + " - Host 3")
if err != nil {
t.Fatal(err)
}
defer stH2.server.Close()
defer stH2.server.panicClose()
stH3, err := blankServerTester(t.Name() + " - Host 4")
if err != nil {
t.Fatal(err)
}
defer stH3.server.Close()
defer stH3.server.panicClose()
testGroup := []*serverTester{st, stH1, stH2, stH3}
// Connect the testers to eachother so that they are all on the same
......@@ -541,7 +544,7 @@ func TestRenterUploadDownload(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer st.server.Close()
defer st.server.panicClose()
// Announce the host and start accepting contracts.
err = st.announceHost()
......@@ -667,7 +670,7 @@ func TestRenterCancelAllowance(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer st.server.Close()
defer st.server.panicClose()
// Announce the host and start accepting contracts.
err = st.announceHost()
......@@ -747,7 +750,7 @@ func TestRenterParallelDelete(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer st.server.Close()
defer st.server.panicClose()
// Announce the host and start accepting contracts.
err = st.announceHost()
......@@ -856,7 +859,7 @@ func TestRenterRenew(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer st.server.Close()
defer st.server.panicClose()
// Announce the host and start accepting contracts.
err = st.announceHost()
......@@ -972,7 +975,7 @@ func TestRenterAllowance(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer st.server.Close()
defer st.server.panicClose()
// Announce the host and start accepting contracts.
err = st.announceHost()
......@@ -1172,7 +1175,7 @@ func TestHostAndRentReload(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer st.server.Close()
defer st.server.panicClose()
err = st.announceHost()
if err != nil {
t.Fatal(err)
......
......@@ -16,7 +16,7 @@ func TestExplorerPreset(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer st.server.Close()
defer st.server.panicClose()
// Try calling a legal endpoint without a user agent.
err = st.stdGetAPIUA("/explorer", "")
......@@ -46,7 +46,7 @@ func TestReloading(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer rst.server.Close()
defer rst.server.panicClose()
if height != rst.server.api.cs.Height() {
t.Error("server heights do not match")
}
......@@ -73,7 +73,7 @@ func TestAuthentication(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer st.server.Close()
defer st.server.panicClose()
testGETURL := "http://" + st.server.listener.Addr().String() + "/wallet/seeds"
testPOSTURL := "http://" + st.server.listener.Addr().String() + "/host/announce"
......
......@@ -69,7 +69,7 @@ func TestWalletGETEncrypted(t *testing.T) {
t.Fatalf("API server quit: %v", err)
}
}()
defer st.server.Close()
defer st.server.panicClose()
var wg WalletGET
err = st.getAPI("/wallet", &wg)
......@@ -130,7 +130,7 @@ func TestWalletEncrypt(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer st2.server.Close()
defer st2.server.panicClose()
// lock the wallet
err = st2.stdPostAPI("/wallet/lock", nil)
......@@ -193,7 +193,7 @@ func TestWalletBlankEncrypt(t *testing.T) {
panic(listenErr)
}
}()
defer st.server.Close()
defer st.server.panicClose()
// Make a call to /wallet/init and get the seed. Provide no encryption
// key so that the encryption key is the seed that gets returned.
......@@ -257,7 +257,7 @@ func TestIntegrationWalletInitSeed(t *testing.T) {
panic(listenErr)
}
}()
defer st.server.Close()
defer st.server.panicClose()
// Make a call to /wallet/init/seed using an invalid seed
qs := url.Values{}
......@@ -309,7 +309,7 @@ func TestWalletGETSiacoins(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer st.server.Close()
defer st.server.panicClose()
// Check the initial wallet is encrypted, unlocked, and has the siacoins
// that got mined.
......@@ -403,7 +403,7 @@ func TestIntegrationWalletSweepSeedPOST(t *testing.T) {
if err != nil {
t.Fatal(err)
}