Skip to content

Commit

Permalink
services/horizon: Improves test cleanup process in case of subtest pa…
Browse files Browse the repository at this point in the history
…nics. (#3059)
  • Loading branch information
Shaptic authored Sep 29, 2020
1 parent a06219a commit 8535626
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
func TestClaimableBalanceCreationOperationsAndEffects(t *testing.T) {
tt := assert.New(t)
itest := test.NewIntegrationTest(t, protocol14Config)
defer itest.Close()
master := itest.Master()

t.Run("Successful", func(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
func TestSponsoredAccount(t *testing.T) {
tt := assert.New(t)
itest := test.NewIntegrationTest(t, protocol14Config)
defer itest.Close()
sponsor := itest.MasterAccount
sponsorPair := itest.Master()

Expand Down Expand Up @@ -214,7 +213,6 @@ func TestSponsoredAccount(t *testing.T) {
func TestSponsoredSigner(t *testing.T) {
tt := assert.New(t)
itest := test.NewIntegrationTest(t, protocol14Config)
defer itest.Close()
sponsorPair := itest.Master()
sponsor := itest.MasterAccount

Expand Down Expand Up @@ -376,7 +374,6 @@ func TestSponsoredSigner(t *testing.T) {
func TestSponsoredPreAuthSigner(t *testing.T) {
tt := assert.New(t)
itest := test.NewIntegrationTest(t, protocol14Config)
defer itest.Close()
sponsorPair := itest.Master()
sponsor := itest.MasterAccount

Expand Down Expand Up @@ -526,7 +523,6 @@ func TestSponsoredPreAuthSigner(t *testing.T) {
func TestSponsoredData(t *testing.T) {
tt := assert.New(t)
itest := test.NewIntegrationTest(t, protocol14Config)
defer itest.Close()
sponsorPair := itest.Master()
sponsor := itest.MasterAccount

Expand Down Expand Up @@ -683,7 +679,6 @@ func TestSponsoredData(t *testing.T) {
func TestSponsoredTrustlineAndOffer(t *testing.T) {
tt := assert.New(t)
itest := test.NewIntegrationTest(t, protocol14Config)
defer itest.Close()
sponsorPair := itest.Master()
sponsor := itest.MasterAccount

Expand Down Expand Up @@ -884,7 +879,6 @@ func TestSponsoredTrustlineAndOffer(t *testing.T) {
func TestSponsoredClaimableBalance(t *testing.T) {
tt := assert.New(t)
itest := test.NewIntegrationTest(t, protocol14Config)
defer itest.Close()
sponsorPair := itest.Master()
sponsor := itest.MasterAccount

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (

func TestProtocol14StateVerifier(t *testing.T) {
itest := test.NewIntegrationTest(t, protocol14Config)
defer itest.Close()

sponsored := keypair.MustRandom()
sponsoredSource := &txnbuild.SimpleAccount{
Expand Down
5 changes: 0 additions & 5 deletions services/horizon/internal/integration/protocol14_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ func TestProtocol14Basics(t *testing.T) {
tt := assert.New(t)

itest := test.NewIntegrationTest(t, protocol14Config)
defer itest.Close()
master := itest.Master()

root, err := itest.Client().Root()
Expand All @@ -44,8 +43,6 @@ func TestProtocol14Basics(t *testing.T) {

func TestHappyClaimableBalances(t *testing.T) {
itest := test.NewIntegrationTest(t, protocol14Config)
defer itest.Close()

master, client := itest.Master(), itest.Client()

keys, accounts := itest.CreateAccounts(3, "1000")
Expand Down Expand Up @@ -238,7 +235,6 @@ func TestHappyClaimableBalances(t *testing.T) {
// We want to ensure that users can't claim the same claimable balance twice.
func TestDoubleClaim(t *testing.T) {
itest := test.NewIntegrationTest(t, protocol14Config)
defer itest.Close()
client := itest.Client()

// Create a couple of accounts to test the interactions.
Expand Down Expand Up @@ -299,7 +295,6 @@ func TestDoubleClaim(t *testing.T) {

func TestClaimableBalancePredicates(t *testing.T) {
itest := test.NewIntegrationTest(t, protocol14Config)
defer itest.Close()
_, client := itest.Master(), itest.Client()

// Create a couple of accounts to test the interactions.
Expand Down
21 changes: 16 additions & 5 deletions services/horizon/internal/test/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import (
"io"
"io/ioutil"
"os"
"os/signal"
"strconv"
"syscall"
"testing"
"time"

Expand Down Expand Up @@ -155,6 +157,18 @@ func NewIntegrationTest(t *testing.T, config IntegrationConfig) *IntegrationTest

doCleanup = false
i.hclient = &sdk.Client{HorizonURL: "http://localhost:8000"}

// Register cleanup handlers (on panic and ctrl+c) so the container is
// removed even if ingestion or testing fails.
i.t.Cleanup(i.Close)
c := make(chan os.Signal)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
go func() {
<-c
i.Close()
os.Exit(0)
}()

i.waitForIngestionAndUpgrade()
return i
}
Expand Down Expand Up @@ -221,19 +235,16 @@ func (i *IntegrationTest) Close() {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
defer cancel()

var err error
skipCreation := os.Getenv("HORIZON_SKIP_CREATION") != ""
if !skipCreation {
i.t.Logf("Removing container %s\n", i.container.ID)
err = i.cli.ContainerRemove(
i.cli.ContainerRemove(
ctx, i.container.ID,
types.ContainerRemoveOptions{Force: true})
} else {
i.t.Logf("Stopping container %s\n", i.container.ID)
err = i.cli.ContainerStop(ctx, i.container.ID, nil)
i.cli.ContainerStop(ctx, i.container.ID, nil)
}

panicIf(err)
}

func createTestContainer(i *IntegrationTest, image string) error {
Expand Down

0 comments on commit 8535626

Please sign in to comment.