How to use GoModDownload method of performance_test Package

Best Ginkgo code snippet using performance_test.GoModDownload

performance_suite_test.go

Source:performance_suite_test.go Github

copy

Full Screen

...121 }122 components := append([]string{f.TmpDir, pkg}, target...)123 return filepath.Join(components...)124}125/* GoModDownload runs go mod download for a given package */126func GoModDownload(fixture string) {127 cmd := exec.Command("go", "mod", "download")128 cmd.Dir = pfm.PathTo(fixture)129 sess, err := gexec.Start(cmd, GinkgoWriter, GinkgoWriter)130 Ω(err).ShouldNot(HaveOccurred())131 Eventually(sess).Should(gexec.Exit(0))132}133/* ScenarioSettings configures the test scenario */134type ScenarioSettings struct {135 Fixture string136 NumSuites int137 Recurse bool138 ClearGoModCache bool139 ConcurrentCompilers int140 ConcurrentRunners int141 CompileFirstSuiteSerially bool142 GoModDownloadFirst bool143 UseGoTestDirectly bool144 ConcurrentGoTests int145 GoTestCompileThenRunSerially bool146 GoTestRecurse bool147}148func (s ScenarioSettings) Name() string {149 out := []string{s.Fixture}150 if s.UseGoTestDirectly {151 if s.GoTestCompileThenRunSerially {152 out = append(out, "go test -c; then run (serially)")153 } else if s.GoTestRecurse {154 out = append(out, "go test ./...")155 } else {156 out = append(out, "go test")157 if s.ConcurrentGoTests == 1 {158 out = append(out, "serially")159 } else {160 out = append(out, fmt.Sprintf("run concurrently [%d]", s.ConcurrentGoTests))161 }162 }163 } else {164 if s.ConcurrentCompilers == 1 {165 out = append(out, "compile serially")166 } else {167 out = append(out, fmt.Sprintf("compile concurrently [%d]", s.ConcurrentCompilers))168 }169 if s.ConcurrentRunners == 1 {170 out = append(out, "run serially")171 } else {172 out = append(out, fmt.Sprintf("run concurrently [%d]", s.ConcurrentRunners))173 }174 if s.CompileFirstSuiteSerially {175 out = append(out, "will compile first suite serially")176 }177 if s.GoModDownloadFirst {178 out = append(out, "will go mod download first")179 }180 }181 return strings.Join(out, " - ")182}183func SampleScenarios(cache gmeasure.ExperimentCache, numSamples int, cacheVersion int, runGoModDownload bool, scenarios ...ScenarioSettings) {184 // we randomize the sample set of scenarios to try to avoid any systematic effects that emerge185 // during the run (e.g. change in internet connection speed, change in computer performance)186 experiments := map[string]*gmeasure.Experiment{}187 runs := []ScenarioSettings{}188 for _, scenario := range scenarios {189 name := scenario.Name()190 if experiment := cache.Load(name, cacheVersion); experiment != nil {191 AddReportEntry(name, experiment, Offset(1), ReportEntryVisibilityFailureOrVerbose)192 continue193 }194 experiments[name] = gmeasure.NewExperiment(name)195 AddReportEntry(name, experiments[name], Offset(1), ReportEntryVisibilityFailureOrVerbose)196 for i := 0; i < numSamples; i++ {197 runs = append(runs, scenario)198 }199 }200 rand.New(rand.NewSource(GinkgoRandomSeed())).Shuffle(len(runs), func(i, j int) {201 runs[i], runs[j] = runs[j], runs[i]202 })203 if len(runs) > 0 && runGoModDownload {204 GoModDownload("performance")205 }206 for idx, run := range runs {207 fmt.Printf("%d - %s\n", idx, run.Name())208 RunScenario(experiments[run.Name()].NewStopwatch(), run, gmeasure.Annotation(fmt.Sprintf("%d", idx+1)))209 }210 for name, experiment := range experiments {211 cache.Save(name, cacheVersion, experiment)212 }213}214func AnalyzeCache(cache gmeasure.ExperimentCache) {215 headers, err := cache.List()216 Ω(err).ShouldNot(HaveOccurred())217 experiments := []*gmeasure.Experiment{}218 for _, header := range headers {219 experiments = append(experiments, cache.Load(header.Name, header.Version))220 }221 for _, measurement := range []string{"first-output", "total-runtime"} {222 stats := []gmeasure.Stats{}223 for _, experiment := range experiments {224 stats = append(stats, experiment.GetStats(measurement))225 }226 AddReportEntry(measurement, gmeasure.RankStats(gmeasure.LowerMedianIsBetter, stats...))227 }228}229func RunScenario(stopwatch *gmeasure.Stopwatch, settings ScenarioSettings, annotation gmeasure.Annotation) {230 if settings.ClearGoModCache {231 gmcm.Clear()232 }233 if settings.GoModDownloadFirst {234 GoModDownload(settings.Fixture)235 stopwatch.Record("mod-download", annotation)236 }237 if settings.UseGoTestDirectly {238 RunScenarioWithGoTest(stopwatch, settings, annotation)239 } else {240 RunScenarioWithGinkgoInternals(stopwatch, settings, annotation)241 }242}243/* CompileAndRun uses the Ginkgo CLIs internals to compile and run tests with different possible settings governing concurrency and ordering */244func RunScenarioWithGinkgoInternals(stopwatch *gmeasure.Stopwatch, settings ScenarioSettings, annotation gmeasure.Annotation) {245 cliConfig := types.NewDefaultCLIConfig()246 cliConfig.Recurse = settings.Recurse247 suiteConfig := types.NewDefaultSuiteConfig()248 reporterConfig := types.NewDefaultReporterConfig()...

Full Screen

Full Screen

GoModDownload

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 test := performance.NewPerformanceTest()4 test.GoModDownload()5 fmt.Printf("The output is: %s", test)6}7import (8func main() {9 test := performance.NewPerformanceTest()10 test.GoModDownload()11 fmt.Printf("The output is: %s", test)12}13import (14func main() {15 test := performance.NewPerformanceTest()16 test.GoModDownload()17 fmt.Printf("The output is: %s", test)18}19import (20func main() {21 test := performance.NewPerformanceTest()22 test.GoModDownload()23 fmt.Printf("The output is: %s", test)24}25import (

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful