Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing profiles will be chosen based on test groups #252

Merged
merged 9 commits into from
Jul 28, 2023
Merged
10 changes: 9 additions & 1 deletion cmd/znet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"time"

"github.com/pkg/errors"
"github.com/samber/lo"
"github.com/spf13/cobra"

"github.com/CoreumFoundation/coreum-tools/pkg/logger"
Expand Down Expand Up @@ -103,7 +104,14 @@ func testCmd(ctx context.Context, configF *infra.ConfigFactory, cmdF *znet.CmdFa
Use: "test",
Short: "Runs integration tests for all repos",
RunE: cmdF.Cmd(func() error {
configF.Profiles = apps.IntegrationTestsProfiles()
if lo.Some(configF.TestGroups, []string{apps.TestGroupCoreumIBC, apps.TestGroupCoreumUpgrade}) || len(configF.TestGroups) == 0 {
configF.Profiles = []string{apps.ProfileIntegrationTestsIBC}
} else {
configF.Profiles = []string{apps.ProfileIntegrationTestsModules}
}
if lo.Contains(configF.TestGroups, apps.TestGroupFaucet) {
configF.Profiles = append(configF.Profiles, apps.ProfileFaucet)
}
spec := infra.NewSpec(configF)
config := znet.NewConfig(configF, spec)
return znet.Test(ctx, config, spec)
Expand Down
138 changes: 78 additions & 60 deletions infra/apps/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ import (
"github.com/CoreumFoundation/crust/infra/apps/relayercosmos"
)

// TestGroup constant values.
const (
TestGroupCoreumModules = "coreum-modules"
TestGroupCoreumUpgrade = "coreum-upgrade"
TestGroupCoreumIBC = "coreum-ibc"
TestGroupFaucet = "faucet"
)

// AppPrefix constants are the prefixes used in the app factories.
const (
AppPrefixCored = "cored"
Expand All @@ -21,31 +29,33 @@ const (
AppPrefixMonitoring = "monitoring"
)

// Predefined Profiles.
const (
profile1Cored = "1cored"
profile3Cored = "3cored"
profile5Cored = "5cored"
profileIBC = "ibc"
profileFaucet = "faucet"
profileExplorer = "explorer"
profileMonitoring = "monitoring"
profileIntegrationTests = "integration-tests"
Profile1Cored = "1cored"
Profile3Cored = "3cored"
Profile5Cored = "5cored"
ProfileIBC = "ibc"
ProfileFaucet = "faucet"
ProfileExplorer = "explorer"
ProfileMonitoring = "monitoring"
ProfileIntegrationTestsIBC = "integration-tests-ibc"
ProfileIntegrationTestsModules = "integration-tests-modules"
)

var profiles = []string{
profile1Cored,
profile3Cored,
profile5Cored,
profileIBC,
profileFaucet,
profileExplorer,
profileMonitoring,
profileIntegrationTests,
Profile1Cored,
Profile3Cored,
Profile5Cored,
ProfileIBC,
ProfileFaucet,
ProfileExplorer,
ProfileMonitoring,
ProfileIntegrationTestsIBC,
ProfileIntegrationTestsModules,
}

var (
defaultProfiles = []string{profile1Cored}
integrationTestsProfiles = []string{profileIntegrationTests}
defaultProfiles = []string{Profile1Cored}
)

var availableProfiles = func() map[string]struct{} {
Expand All @@ -66,58 +76,35 @@ func DefaultProfiles() []string {
return defaultProfiles
}

// IntegrationTestsProfiles returns the list of profiles started for integration tests.
func IntegrationTestsProfiles() []string {
return integrationTestsProfiles
}

// BuildAppSet builds the application set to deploy based on provided profiles.
func BuildAppSet(appF *Factory, profiles []string, coredVersion string) (infra.AppSet, error) {
pMap := map[string]bool{}
coredProfilePresent := false
for _, p := range profiles {
if _, ok := availableProfiles[p]; !ok {
return nil, errors.Errorf("profile %s does not exist", p)
}
if p == profile1Cored || p == profile3Cored || p == profile5Cored {
if coredProfilePresent {
return nil, errors.Errorf("profiles 1cored, 3cored and 5cored are mutually exclusive")
}
coredProfilePresent = true
}
pMap[p] = true
pMap, err := checkProfiles(profiles)
if err != nil {
return nil, err
}

if pMap[profileIntegrationTests] {
if pMap[profile1Cored] {
if pMap[ProfileIntegrationTestsIBC] || pMap[ProfileIntegrationTestsModules] {
if pMap[Profile1Cored] {
return nil, errors.Errorf("profile 1cored can't be used together with integration-tests as it requires 3cored or 5cored")
}
if !pMap[profile5Cored] {
pMap[profile3Cored] = true
if !pMap[Profile5Cored] {
pMap[Profile3Cored] = true
}
pMap[profileIBC] = true
pMap[profileFaucet] = true
}

if (pMap[profileIBC] || pMap[profileFaucet] || pMap[profileExplorer] || pMap[profileMonitoring]) && !pMap[profile3Cored] && !pMap[profile5Cored] {
pMap[profile1Cored] = true
if pMap[ProfileIntegrationTestsIBC] {
pMap[ProfileIBC] = true
}

var numOfCoredValidators int
switch {
case pMap[profile1Cored]:
numOfCoredValidators = 1
case pMap[profile3Cored]:
numOfCoredValidators = 3
case pMap[profile5Cored]:
numOfCoredValidators = 5
if (pMap[ProfileIBC] || pMap[ProfileFaucet] || pMap[ProfileExplorer] || pMap[ProfileMonitoring]) && !pMap[Profile3Cored] && !pMap[Profile5Cored] {
pMap[Profile1Cored] = true
}

numOfCoredValidators := decideNumOfCoredValidators(pMap)

var coredApp cored.Cored
var appSet infra.AppSet

var err error

coredApp, coredNodes, err := appF.CoredNetwork(AppPrefixCored, cored.DefaultPorts, numOfCoredValidators, 0, coredVersion)
if err != nil {
return nil, err
Expand All @@ -126,21 +113,20 @@ func BuildAppSet(appF *Factory, profiles []string, coredVersion string) (infra.A
appSet = append(appSet, coredNode)
}

if pMap[profileIBC] {
if pMap[ProfileIBC] {
appSet = append(appSet, appF.IBC(AppPrefixIBC, coredApp)...)
}

var faucetApp faucet.Faucet
if pMap[profileFaucet] {
faucetApp = appF.Faucet(string(faucet.AppType), coredApp)
appSet = append(appSet, faucetApp)
if pMap[ProfileFaucet] {
appSet = append(appSet, appF.Faucet(string(faucet.AppType), coredApp))
}

if pMap[profileExplorer] {
if pMap[ProfileExplorer] {
appSet = append(appSet, appF.BlockExplorer(AppPrefixExplorer, coredApp).ToAppSet()...)
}

if pMap[profileMonitoring] {
if pMap[ProfileMonitoring] {
var bdJunoApp bdjuno.BDJuno
if bdJunoAppSetApp, ok := appSet.FindAppByName(
BuildPrefixedAppName(AppPrefixExplorer, string(bdjuno.AppType)),
Expand Down Expand Up @@ -174,3 +160,35 @@ func BuildAppSet(appF *Factory, profiles []string, coredVersion string) (infra.A

return appSet, nil
}

func decideNumOfCoredValidators(pMap map[string]bool) int {
switch {
case pMap[Profile1Cored]:
return 1
case pMap[Profile3Cored]:
return 3
case pMap[Profile5Cored]:
return 5
default:
panic("no cored profile specified.")
}
}

func checkProfiles(profiles []string) (map[string]bool, error) {
pMap := map[string]bool{}
coredProfilePresent := false
for _, p := range profiles {
if _, ok := availableProfiles[p]; !ok {
return nil, errors.Errorf("profile %s does not exist", p)
}
if p == Profile1Cored || p == Profile3Cored || p == Profile5Cored {
if coredProfilePresent {
return nil, errors.Errorf("profiles 1cored, 3cored and 5cored are mutually exclusive")
}
coredProfilePresent = true
}
pMap[p] = true
}

return pMap, nil
}
13 changes: 3 additions & 10 deletions infra/testing/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,14 @@ func Run(ctx context.Context, target infra.Target, appSet infra.AppSet, config i
args = append(args, "-test.run", config.TestFilter)
}

const (
testGroupCoreumModules = "coreum-modules"
testGroupCoreumUpgrade = "coreum-upgrade"
testGroupCoreumIBC = "coreum-ibc"
testGroupFaucet = "faucet"
)

var failed bool
// the execution order might be important
for _, onlyTestGroup := range onlyTestGroups {
// copy is not used here, since the linter complains in the next line that using append with pre-allocated
// length leads to extra space getting allocated.
fullArgs := append([]string{}, args...)
switch onlyTestGroup {
case testGroupCoreumModules, testGroupCoreumUpgrade, testGroupCoreumIBC:
case apps.TestGroupCoreumModules, apps.TestGroupCoreumUpgrade, apps.TestGroupCoreumIBC:

fullArgs = append(fullArgs,
"-run-unsafe=true",
Expand All @@ -108,7 +101,7 @@ func Run(ctx context.Context, target infra.Target, appSet infra.AppSet, config i
}
}

if onlyTestGroup == testGroupCoreumIBC {
if onlyTestGroup == apps.TestGroupCoreumIBC {
fullArgs = append(fullArgs, "-coreum-rpc-address", infra.JoinNetAddr("http", coredNode.Info().HostFromHost, coredNode.Config().Ports.RPC))

gaiaNode := appSet.FindRunningAppByName(apps.BuildPrefixedAppName(apps.AppPrefixIBC, string(gaiad.AppType)))
Expand Down Expand Up @@ -136,7 +129,7 @@ func Run(ctx context.Context, target infra.Target, appSet infra.AppSet, config i
)
}

case testGroupFaucet:
case apps.TestGroupFaucet:
faucetApp := appSet.FindRunningAppByName(string(faucet.AppType))
if faucetApp == nil {
return errors.New("no running faucet app found")
Expand Down
Loading