Skip to content

Commit

Permalink
ffs/integrationtest: paralellize
Browse files Browse the repository at this point in the history
Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
  • Loading branch information
jsign committed Apr 24, 2020
1 parent 415e4d4 commit 0c50452
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ build: build-cli build-server
.PHONY: build

test:
go test -short -p 1 -race ./...
go test -short -p 4 race ./...
.PHONY: test
29 changes: 26 additions & 3 deletions ffs/integrationtest/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const (
)

func TestMain(m *testing.M) {
util.AvgBlockTime = time.Millisecond * 500
_ = os.RemoveAll(tmpDir)
if _, err := os.Stat(tmpDir); os.IsNotExist(err) {
if err := os.Mkdir(tmpDir, os.ModePerm); err != nil {
Expand All @@ -61,6 +62,7 @@ func TestMain(m *testing.M) {
}

func TestSetDefaultConfig(t *testing.T) {
t.Parallel()
_, fapi, cls := newAPI(t, 1)
defer cls()

Expand Down Expand Up @@ -88,6 +90,7 @@ func TestSetDefaultConfig(t *testing.T) {
}

func TestAddrs(t *testing.T) {
t.Parallel()
_, fapi, cls := newAPI(t, 1)
defer cls()

Expand All @@ -98,6 +101,7 @@ func TestAddrs(t *testing.T) {
}

func TestNewAddress(t *testing.T) {
t.Parallel()
_, fapi, cls := newAPI(t, 1)
defer cls()

Expand All @@ -110,6 +114,7 @@ func TestNewAddress(t *testing.T) {
}

func TestNewAddressDefault(t *testing.T) {
t.Parallel()
_, fapi, cls := newAPI(t, 1)
defer cls()

Expand All @@ -122,6 +127,7 @@ func TestNewAddressDefault(t *testing.T) {
}

func TestGetDefaultConfig(t *testing.T) {
t.Parallel()
_, fapi, cls := newAPI(t, 1)
defer cls()

Expand All @@ -130,6 +136,7 @@ func TestGetDefaultConfig(t *testing.T) {
}

func TestAdd(t *testing.T) {
t.Parallel()
r := rand.New(rand.NewSource(22))
t.Run("WithDefaultConfig", func(t *testing.T) {
ctx := context.Background()
Expand Down Expand Up @@ -163,6 +170,7 @@ func TestAdd(t *testing.T) {
}

func TestGet(t *testing.T) {
t.Parallel()
ctx := context.Background()
ipfs, fapi, cls := newAPI(t, 1)
defer cls()
Expand All @@ -184,6 +192,7 @@ func TestGet(t *testing.T) {
}

func TestInfo(t *testing.T) {
t.Parallel()
ctx := context.Background()
ipfs, fapi, cls := newAPI(t, 1)
defer cls()
Expand Down Expand Up @@ -222,6 +231,7 @@ func TestInfo(t *testing.T) {
}

func TestShow(t *testing.T) {
t.Parallel()
ctx := context.Background()
ipfs, fapi, cls := newAPI(t, 1)

Expand Down Expand Up @@ -264,6 +274,7 @@ func TestShow(t *testing.T) {
}

func TestColdInstanceLoad(t *testing.T) {
t.Parallel()
ctx := context.Background()
ipfsDocker, cls := tests.LaunchIPFSDocker()
t.Cleanup(func() { cls() })
Expand Down Expand Up @@ -303,6 +314,7 @@ func TestColdInstanceLoad(t *testing.T) {
}

func TestRepFactor(t *testing.T) {
t.Parallel()
rfs := []int{1, 2}
r := rand.New(rand.NewSource(22))
for _, rf := range rfs {
Expand All @@ -324,6 +336,7 @@ func TestRepFactor(t *testing.T) {
}

func TestRepFactorIncrease(t *testing.T) {
t.Parallel()
r := rand.New(rand.NewSource(22))
ipfsAPI, fapi, cls := newAPI(t, 2)
defer cls()
Expand All @@ -350,6 +363,7 @@ func TestRepFactorIncrease(t *testing.T) {
}

func TestRepFactorDecrease(t *testing.T) {
t.Parallel()
r := rand.New(rand.NewSource(22))
ipfsAPI, fapi, cls := newAPI(t, 2)
defer cls()
Expand Down Expand Up @@ -377,6 +391,7 @@ func TestRepFactorDecrease(t *testing.T) {
}

func TestHotTimeoutConfig(t *testing.T) {
t.Parallel()
_, fapi, cls := newAPI(t, 1)
defer cls()

Expand All @@ -390,6 +405,7 @@ func TestHotTimeoutConfig(t *testing.T) {
}

func TestDurationConfig(t *testing.T) {
t.Parallel()
ipfsAPI, fapi, cls := newAPI(t, 1)
defer cls()

Expand All @@ -409,6 +425,7 @@ func TestDurationConfig(t *testing.T) {
}

func TestFilecoinExcludedMiners(t *testing.T) {
t.Parallel()
ipfsAPI, fapi, cls := newAPI(t, 2)
defer cls()

Expand All @@ -428,6 +445,7 @@ func TestFilecoinExcludedMiners(t *testing.T) {
}

func TestFilecoinCountryFilter(t *testing.T) {
t.Parallel()
ipfsDocker, cls := tests.LaunchIPFSDocker()
t.Cleanup(func() { cls() })

Expand Down Expand Up @@ -463,6 +481,7 @@ func TestFilecoinCountryFilter(t *testing.T) {
}

func TestFilecoinEnableConfig(t *testing.T) {
t.Parallel()
tableTest := []struct {
HotEnabled bool
ColdEnabled bool
Expand Down Expand Up @@ -546,6 +565,7 @@ func requireIpfsPinnedCid(ctx context.Context, t *testing.T, cid cid.Cid, ipfsAP
}

func TestEnabledConfigChange(t *testing.T) {
t.Parallel()
t.Run("HotEnabledDisabled", func(t *testing.T) {
ctx := context.Background()
ipfsAPI, fapi, cls := newAPI(t, 1)
Expand Down Expand Up @@ -665,6 +685,7 @@ func requireFilStored(ctx context.Context, t *testing.T, client *apistruct.FullN
}

func TestUnfreeze(t *testing.T) {
t.Parallel()
ipfsAPI, fapi, cls := newAPI(t, 1)
defer cls()

Expand Down Expand Up @@ -697,7 +718,7 @@ func TestUnfreeze(t *testing.T) {
}

func TestRenew(t *testing.T) {
util.AvgBlockTime = time.Millisecond * 200
t.Parallel()
ipfsDocker, cls := tests.LaunchIPFSDocker()
t.Cleanup(func() { cls() })
ds := tests.NewTxMapDatastore()
Expand Down Expand Up @@ -751,7 +772,6 @@ func TestRenewWithDecreasedRepFactor(t *testing.T) {
// ToDo: unskip when testnet/3 allows more than one deal
// See https://bit.ly/2JxQSQk
t.SkipNow()
util.AvgBlockTime = time.Millisecond * 200
ipfsDocker, cls := tests.LaunchIPFSDocker()
t.Cleanup(func() { cls() })
ds := tests.NewTxMapDatastore()
Expand Down Expand Up @@ -808,6 +828,7 @@ Loop:
}

func TestCidLogger(t *testing.T) {
t.Parallel()
t.Run("WithNoFilters", func(t *testing.T) {
ipfs, fapi, cls := newAPI(t, 1)
defer cls()
Expand Down Expand Up @@ -916,6 +937,7 @@ func TestCidLogger(t *testing.T) {
}

func TestPushCidReplace(t *testing.T) {
t.Parallel()
ctx := context.Background()
ipfsDocker, cls := tests.LaunchIPFSDocker()
defer cls()
Expand Down Expand Up @@ -958,6 +980,7 @@ func TestPushCidReplace(t *testing.T) {
}

func TestRemove(t *testing.T) {
t.Parallel()
ipfs, fapi, cls := newAPI(t, 1)
defer cls()

Expand Down Expand Up @@ -991,7 +1014,7 @@ func TestRemove(t *testing.T) {
// Better than no test is some test, so this tests that the repair logic gets triggered
// and the related Job ran successfully.
func TestRepair(t *testing.T) {
util.AvgBlockTime = time.Second
t.Parallel()
ipfs, fapi, cls := newAPI(t, 1)
defer cls()

Expand Down
13 changes: 6 additions & 7 deletions index/slashing/slashing.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ func (s *Index) start() {
log.Info("graceful shutdown of background slashing updater")
return
case <-time.After(util.AvgBlockTime):

if err := s.updateIndex(); err != nil {
log.Errorf("error when updating slashing history: %s", err)
continue
Expand All @@ -145,27 +144,27 @@ func (s *Index) updateIndex() error {
log.Info("updating slashing index...")
heaviest, err := s.api.ChainHead(s.ctx)
if err != nil {
return err
return fmt.Errorf("getting chain head: %s", err)
}
if heaviest.Height()-hOffset <= 0 {
return nil
}
new, err := s.api.ChainGetTipSetByHeight(s.ctx, heaviest.Height()-hOffset, heaviest.Key())
if err != nil {
return err
return fmt.Errorf("get tipset by height: %s", err)
}
newtsk := types.NewTipSetKey(new.Cids()...)
var index IndexSnapshot
ts, err := s.store.LoadAndPrune(s.ctx, newtsk, &index)
if err != nil {
return err
return fmt.Errorf("load tipset state: %s", err)
}
if index.Miners == nil {
index.Miners = make(map[string]Slashes)
}
_, path, err := chainsync.ResolveBase(s.ctx, s.api, ts, newtsk)
if err != nil {
return err
return fmt.Errorf("resolving base path: %s", err)
}
mctx := context.Background()
start := time.Now()
Expand All @@ -175,10 +174,10 @@ func (s *Index) updateIndex() error {
j = len(path)
}
if err := updateFromPath(s.ctx, s.api, &index, path[i:j]); err != nil {
return err
return fmt.Errorf("getting update from path section: %s", err)
}
if err := s.store.Save(s.ctx, types.NewTipSetKey(path[j-1].Cids()...), index); err != nil {
return err
return fmt.Errorf("saving new index state: %s", err)
}
log.Infof("processed from %d to %d", path[i].Height(), path[j-1].Height())
s.lock.Lock()
Expand Down
2 changes: 1 addition & 1 deletion index/slashing/slashing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

func TestMain(m *testing.M) {
util.AvgBlockTime = time.Millisecond * 10
util.AvgBlockTime = time.Millisecond * 100
logging.SetAllLoggers(logging.LevelError)
os.Exit(m.Run())
}
Expand Down
3 changes: 2 additions & 1 deletion tests/ldevnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ func LaunchDevnetDocker(t *testing.T, numMiners int) *dockertest.Resource {
panic(fmt.Sprintf("couldn't create ipfs-pool: %s", err))
}
envNumMiners := fmt.Sprintf("TEXLOTUSDEVNET_NUMMINERS=%d", numMiners)
lotusDevnet, err := pool.RunWithOptions(&dockertest.RunOptions{Repository: "textile/lotus-devnet", Tag: "sha-c755791", Env: []string{envNumMiners}, Mounts: []string{"/tmp/powergate:/tmp/powergate"}})
speed := "TEXLOTUSDEVNET_SPEED=500"
lotusDevnet, err := pool.RunWithOptions(&dockertest.RunOptions{Repository: "textile/lotus-devnet", Tag: "sha-c755791", Env: []string{envNumMiners, speed}, Mounts: []string{"/tmp/powergate:/tmp/powergate"}})
if err != nil {
panic(fmt.Sprintf("couldn't run lotus-devnet container: %s", err))
}
Expand Down

0 comments on commit 0c50452

Please sign in to comment.