diff --git a/pkg/openevec/config.go b/pkg/openevec/config.go index 5a8f0194b..acca19d15 100644 --- a/pkg/openevec/config.go +++ b/pkg/openevec/config.go @@ -28,15 +28,17 @@ type ImagesConfig struct { } type EdenConfig struct { - Download bool `mapstructure:"download" cobraflag:"download"` - BinDir string `mapstructure:"bin-dist" cobraflag:"bin-dist" resolvepath:""` - CertsDir string `mapstructure:"certs-dist" cobraflag:"certs-dist" resolvepath:""` - Dist string `mapstructure:"dist"` - Root string `mapstructure:"root"` - SSHKey string `mapstructure:"ssh-key" cobraflag:"ssh-key" resolvepath:""` - EdenBin string `mapstructure:"eden-bin"` - TestBin string `mapstructure:"test-bin"` - TestScenario string `mapstructure:"test-scenario"` + Download bool `mapstructure:"download" cobraflag:"download"` + BinDir string `mapstructure:"bin-dist" cobraflag:"bin-dist" resolvepath:""` + CertsDir string `mapstructure:"certs-dist" cobraflag:"certs-dist" resolvepath:""` + Dist string `mapstructure:"dist"` + Root string `mapstructure:"root"` + SSHKey string `mapstructure:"ssh-key" cobraflag:"ssh-key" resolvepath:""` + EdenBin string `mapstructure:"eden-bin"` + + TestBin string `mapstructure:"test-bin"` + TestScenario string `mapstructure:"test-scenario"` + TestTimeDilation float32 `mapstructure:"test-time-dilation"` EServer EServerConfig `mapstructure:"eserver"` diff --git a/pkg/openevec/defaults.go b/pkg/openevec/defaults.go index 928841da8..bed2784f8 100644 --- a/pkg/openevec/defaults.go +++ b/pkg/openevec/defaults.go @@ -28,6 +28,7 @@ func GetDefaultConfig() *EdenSetupArgs { Force: false, Tag: defaults.DefaultEServerTag, }, + TestTimeDilation: 1.0, }, Adam: AdamConfig{ diff --git a/pkg/openevec/test.go b/pkg/openevec/test.go index 62958e6ec..1f59c5b21 100644 --- a/pkg/openevec/test.go +++ b/pkg/openevec/test.go @@ -61,6 +61,7 @@ func InitVarsFromConfig(cfg *EdenSetupArgs) (*utils.ConfigVars, error) { cv.EServerImageDist = utils.ResolveAbsPath(cfg.Eden.Images.EServerImageDist) cv.EServerPort = strconv.Itoa(cfg.Eden.EServer.Port) cv.EServerIP = cfg.Eden.EServer.IP + cv.ExecCmdTimeDilation = cfg.Eden.TestTimeDilation cv.EveCert = utils.ResolveAbsPath(cfg.Eve.Cert) cv.EveDeviceCert = utils.ResolveAbsPath(cfg.Eve.DeviceCert) diff --git a/pkg/utils/config.go b/pkg/utils/config.go index a758e0728..f05a0c1db 100644 --- a/pkg/utils/config.go +++ b/pkg/utils/config.go @@ -23,45 +23,46 @@ var viperAccessMutex sync.RWMutex // ConfigVars struct with parameters from config file type ConfigVars struct { - AdamIP string - AdamPort string - AdamDomain string - AdamDir string - AdamCA string - AdamRemote bool - AdamCaching bool - AdamCachingRedis bool - AdamCachingPrefix string - AdamRemoteRedis bool - AdamRedisURLEden string - AdamRedisURLAdam string - EveHV string - EveSSID string - EveUUID string - EveName string - EveRemote bool - EveRemoteAddr string - EveQemuPorts map[string]string - EveQemuConfig string - EveDist string - SSHKey string - EveCert string - EveDeviceCert string - EveSerial string - ZArch string - DevModel string - DevModelFIle string - EdenBinDir string - EdenProg string - TestProg string - TestScenario string - EServerImageDist string - EServerPort string - EServerIP string - RegistryIP string - RegistryPort string - LogLevel string - AdamLogLevel string + AdamIP string + AdamPort string + AdamDomain string + AdamDir string + AdamCA string + AdamRemote bool + AdamCaching bool + AdamCachingRedis bool + AdamCachingPrefix string + AdamRemoteRedis bool + AdamRedisURLEden string + AdamRedisURLAdam string + EveHV string + EveSSID string + EveUUID string + EveName string + EveRemote bool + EveRemoteAddr string + EveQemuPorts map[string]string + EveQemuConfig string + EveDist string + SSHKey string + EveCert string + EveDeviceCert string + EveSerial string + ZArch string + DevModel string + DevModelFIle string + EdenBinDir string + EdenProg string + TestProg string + TestScenario string + EServerImageDist string + EServerPort string + EServerIP string + RegistryIP string + RegistryPort string + LogLevel string + AdamLogLevel string + ExecCmdTimeDilation float32 } // InitVars loads vars from viper @@ -91,44 +92,46 @@ func InitVars() (*ConfigVars, error) { caCertPath := filepath.Join(globalCertsDir, "root-certificate.pem") viperAccessMutex.RLock() var vars = &ConfigVars{ - AdamIP: viper.GetString("adam.ip"), - AdamPort: viper.GetString("adam.port"), - AdamDomain: viper.GetString("adam.domain"), - AdamDir: ResolveAbsPath(viper.GetString("adam.dist")), - AdamCA: caCertPath, - AdamRedisURLEden: viper.GetString("adam.redis.eden"), - SSHKey: ResolveAbsPath(viper.GetString("eden.ssh-key")), - EveCert: ResolveAbsPath(viper.GetString("eve.cert")), - EveDeviceCert: ResolveAbsPath(viper.GetString("eve.device-cert")), - EveSerial: viper.GetString("eve.serial"), - EveDist: viper.GetString("eve.dist"), - EveQemuConfig: viper.GetString("eve.qemu-config"), - ZArch: viper.GetString("eve.arch"), - EveSSID: viper.GetString("eve.ssid"), - EveHV: viper.GetString("eve.hv"), - DevModel: viper.GetString("eve.devmodel"), - DevModelFIle: viper.GetString("eve.devmodelfile"), - EveName: viper.GetString("eve.name"), - EveUUID: viper.GetString("eve.uuid"), - EveRemote: viper.GetBool("eve.remote"), - EveRemoteAddr: viper.GetString("eve.remote-addr"), - EveQemuPorts: viper.GetStringMapString("eve.hostfwd"), - AdamRemote: viper.GetBool("adam.remote.enabled"), - AdamRemoteRedis: viper.GetBool("adam.remote.redis"), - AdamCaching: viper.GetBool("adam.caching.enabled"), - AdamCachingPrefix: viper.GetString("adam.caching.prefix"), - AdamCachingRedis: viper.GetBool("adam.caching.redis"), - EdenBinDir: viper.GetString("eden.bin-dist"), - EdenProg: viper.GetString("eden.eden-bin"), - TestProg: viper.GetString("eden.test-bin"), - TestScenario: viper.GetString("eden.test-scenario"), - EServerImageDist: ResolveAbsPath(viper.GetString("eden.images.dist")), - EServerPort: viper.GetString("eden.eserver.port"), - EServerIP: viper.GetString("eden.eserver.ip"), - RegistryIP: viper.GetString("registry.ip"), - RegistryPort: viper.GetString("registry.port"), - LogLevel: viper.GetString("eve.log-level"), - AdamLogLevel: viper.GetString("eve.adam-log-level"), + AdamIP: viper.GetString("adam.ip"), + AdamPort: viper.GetString("adam.port"), + AdamDomain: viper.GetString("adam.domain"), + AdamDir: ResolveAbsPath(viper.GetString("adam.dist")), + AdamCA: caCertPath, + AdamRemote: viper.GetBool("adam.remote.enabled"), + AdamCaching: viper.GetBool("adam.caching.enabled"), + AdamCachingRedis: viper.GetBool("adam.caching.redis"), + AdamCachingPrefix: viper.GetString("adam.caching.prefix"), + AdamRemoteRedis: viper.GetBool("adam.remote.redis"), + AdamRedisURLEden: viper.GetString("adam.redis.eden"), + AdamRedisURLAdam: "", + EveHV: viper.GetString("eve.hv"), + EveSSID: viper.GetString("eve.ssid"), + EveUUID: viper.GetString("eve.uuid"), + EveName: viper.GetString("eve.name"), + EveRemote: viper.GetBool("eve.remote"), + EveRemoteAddr: viper.GetString("eve.remote-addr"), + EveQemuPorts: viper.GetStringMapString("eve.hostfwd"), + EveQemuConfig: viper.GetString("eve.qemu-config"), + EveDist: viper.GetString("eve.dist"), + SSHKey: ResolveAbsPath(viper.GetString("eden.ssh-key")), + EveCert: ResolveAbsPath(viper.GetString("eve.cert")), + EveDeviceCert: ResolveAbsPath(viper.GetString("eve.device-cert")), + EveSerial: viper.GetString("eve.serial"), + ZArch: viper.GetString("eve.arch"), + DevModel: viper.GetString("eve.devmodel"), + DevModelFIle: viper.GetString("eve.devmodelfile"), + EdenBinDir: viper.GetString("eden.bin-dist"), + EdenProg: viper.GetString("eden.eden-bin"), + TestProg: viper.GetString("eden.test-bin"), + TestScenario: viper.GetString("eden.test-scenario"), + EServerImageDist: ResolveAbsPath(viper.GetString("eden.images.dist")), + EServerPort: viper.GetString("eden.eserver.port"), + EServerIP: viper.GetString("eden.eserver.ip"), + RegistryIP: viper.GetString("registry.ip"), + RegistryPort: viper.GetString("registry.port"), + LogLevel: viper.GetString("eve.log-level"), + AdamLogLevel: viper.GetString("eve.adam-log-level"), + ExecCmdTimeDilation: float32(viper.GetFloat64("eden.exec-dilation")), } viperAccessMutex.RUnlock() redisPasswordFile := filepath.Join(globalCertsDir, defaults.DefaultRedisPasswordFile) diff --git a/tests/app/app_test.go b/tests/app/app_test.go index 620889d27..e5ba9b37c 100644 --- a/tests/app/app_test.go +++ b/tests/app/app_test.go @@ -139,67 +139,67 @@ func TestAppStatus(t *testing.T) { args := flag.Args() if len(args) == 0 { t.Fatalf("Usage: %s [options] state app_name...\n", os.Args[0]) - } else { - secs := int(timewait.Seconds()) - state := args[0] - fmt.Printf("apps: '%s' state: '%s' secs: %d\n", - args[1:], state, secs) - - apps := args[1:] - if apps[len(apps)-1] == "&" { - apps = apps[:len(apps)-1] - } - states = make(map[string][]appState) - for _, el := range apps { - states[el] = []appState{{ - state: "no info from controller", - timestamp: time.Now()}} - } + return + } + secs := int(timewait.Seconds()) + state := args[0] + fmt.Printf("apps: '%s' state: '%s' secs: %d\n", + args[1:], state, secs) + + apps := args[1:] + if apps[len(apps)-1] == "&" { + apps = apps[:len(apps)-1] + } + states = make(map[string][]appState) + for _, el := range apps { + states[el] = []appState{{ + state: "no info from controller", + timestamp: time.Now()}} + } - if !*newitems { - // observe existing info object and feed them into eveState object - if err := tc.GetController().InfoLastCallback(edgeNode.GetID(), nil, eveState.InfoCallback()); err != nil { - t.Fatal(err) - } + if !*newitems { + // observe existing info object and feed them into eveState object + if err := tc.GetController().InfoLastCallback(edgeNode.GetID(), nil, eveState.InfoCallback()); err != nil { + t.Fatal(err) } + } - if ready := checkState(eveState, state, apps); ready == nil { + if ready := checkState(eveState, state, apps); ready == nil { - tc.AddProcInfo(edgeNode, checkApp(state, apps)) + tc.AddProcInfo(edgeNode, checkApp(state, apps)) - callback := func() { - t.Errorf("ASSERTION FAILED (%s): expected apps %s in %s state", time.Now().Format(time.RFC3339Nano), apps, state) - for k, v := range states { - t.Errorf("\tactual %s: %s", k, v[len(v)-1].state) - if checkNewLastState(k, state) { - t.Errorf("\thistory of states for %s:", k) - for _, st := range v { - t.Errorf("\t\tstate: %s received in: %s", st.state, st.timestamp.Format(time.RFC3339Nano)) - } + callback := func() { + t.Errorf("ASSERTION FAILED (%s): expected apps %s in %s state", time.Now().Format(time.RFC3339Nano), apps, state) + for k, v := range states { + t.Errorf("\tactual %s: %s", k, v[len(v)-1].state) + if checkNewLastState(k, state) { + t.Errorf("\thistory of states for %s:", k) + for _, st := range v { + t.Errorf("\t\tstate: %s received in: %s", st.state, st.timestamp.Format(time.RFC3339Nano)) } - for _, app := range eveState.Applications() { - if app.Name == k { - appID, err := uuid.FromString(app.UUID) - if err != nil { - t.Fatal(err) - } - fmt.Printf("--- app %s logs ---\n", app.Name) - if err = tc.GetController().LogAppsChecker(edgeNode.GetID(), appID, nil, eapps.HandleFactory(types.OutputFormatJSON, false), eapps.LogExist, 0); err != nil { - t.Fatalf("LogAppsChecker: %s", err) - } - fmt.Println("------") + } + for _, app := range eveState.Applications() { + if app.Name == k { + appID, err := uuid.FromString(app.UUID) + if err != nil { + t.Fatal(err) } + fmt.Printf("--- app %s logs ---\n", app.Name) + if err = tc.GetController().LogAppsChecker(edgeNode.GetID(), appID, nil, eapps.HandleFactory(types.OutputFormatJSON, false), eapps.LogExist, 0); err != nil { + t.Fatalf("LogAppsChecker: %s", err) + } + fmt.Println("------") } } } - - tc.WaitForProcWithErrorCallback(secs, callback) - - } else { - t.Log(utils.AddTimestamp(ready.Error())) } - // sleep to reduce concurrency effects - time.Sleep(1 * time.Second) + tc.WaitForProcWithErrorCallback(secs, callback) + + } else { + t.Log(utils.AddTimestamp(ready.Error())) } + + // sleep to reduce concurrency effects + time.Sleep(1 * time.Second) } diff --git a/tests/escript/go-internal/testscript/cmd.go b/tests/escript/go-internal/testscript/cmd.go index 528efd51d..51edb4f1a 100644 --- a/tests/escript/go-internal/testscript/cmd.go +++ b/tests/escript/go-internal/testscript/cmd.go @@ -53,9 +53,39 @@ var scriptCmds = map[string]func(*TestScript, bool, []string){ "wait": (*TestScript).cmdWait, } -var timewait time.Duration var backgroundSpecifier = regexp.MustCompile(`^&(\w+&)?$`) +var configVars *utils.ConfigVars + +func init() { + var err error + configVars, err = utils.InitVars() + if err != nil { + panic(err) + } +} + +var timewait timew + +type timew struct { + timewait time.Duration +} + +func (t timew) Duration() time.Duration { + return t.timewait +} + +func (t timew) String() string { + return t.timewait.String() +} + +func (t *timew) set(duration time.Duration) { + configVars.ExecCmdTimeDilation = 10 + dilatedDuration := float64(configVars.ExecCmdTimeDilation) * float64(duration) + + t.timewait = time.Duration(dilatedDuration) +} + // cd changes to a different directory. func (ts *TestScript) cmdCd(neg bool, args []string) { if neg { @@ -275,13 +305,12 @@ func (ts *TestScript) cmdEden(neg bool, args []string) { // timewait if len(args) > 0 && args[0] == "-t" { - timewait, err = time.ParseDuration(args[1]) + timeduration, err := time.ParseDuration(args[1]) + timewait.set(timeduration) if err != nil { ts.Fatalf("Incorrect time format in 'eden': %s\n", err) } args = args[2:] - } else { - timewait = 0 } fmt.Printf("edenProg: %s timewait: %s\n", edenProg, timewait) @@ -327,13 +356,12 @@ func (ts *TestScript) cmdTest(neg bool, args []string) { // timewait if len(args) > 0 && args[0] == "-t" { - timewait, err = time.ParseDuration(args[1]) + timeduration, err := time.ParseDuration(args[1]) + timewait.set(timeduration) if err != nil { ts.Fatalf("Incorrect time format in 'test': %s\n", err) } args = args[2:] - } else { - timewait = 0 } testProg := utils.ResolveAbsPath(vars.EdenBinDir + "/" + args[0]) @@ -452,13 +480,12 @@ func (ts *TestScript) cmdExec(neg bool, args []string) { var err error if len(args) > 0 && args[0] == "-t" { - timewait, err = time.ParseDuration(args[1]) + timeduration, err := time.ParseDuration(args[1]) + timewait.set(timeduration) if err != nil { ts.Fatalf("Incorrect time format in 'exec': %s\n", err) } args = args[2:] - } else { - timewait = 0 } fmt.Printf("exec timewait: %s\n", timewait) diff --git a/tests/escript/go-internal/testscript/testscript.go b/tests/escript/go-internal/testscript/testscript.go index 21cf24154..2be69dd3b 100644 --- a/tests/escript/go-internal/testscript/testscript.go +++ b/tests/escript/go-internal/testscript/testscript.go @@ -717,13 +717,13 @@ func (ts *TestScript) buildExecCmd(command string, args ...string) (context.Cont } command = lp } - if timewait == 0 { + if timewait.Duration() == 0 { //ts.ctxt = context.Background() return ts.ctxt, exec.Command(command, args...), nil, nil } //ts.ctxt, _ = context.WithTimeout(context.Background(), timewait) //return exec.CommandContext(ts.ctxt, command, args...), nil - ctx, cancelFunc := context.WithTimeout(ts.ctxt, timewait) + ctx, cancelFunc := context.WithTimeout(ts.ctxt, timewait.Duration()) return ctx, exec.CommandContext(ctx, command, args...), cancelFunc, nil }