diff --git a/systest/backup/advanced-scenarios/127-Namespace/backup_test.go b/systest/backup/advanced-scenarios/127-Namespace/backup_test.go index 7f9ee71faa1..6cdbf1da250 100755 --- a/systest/backup/advanced-scenarios/127-Namespace/backup_test.go +++ b/systest/backup/advanced-scenarios/127-Namespace/backup_test.go @@ -1,3 +1,5 @@ +//go:build integration + package main import ( diff --git a/t/t.go b/t/t.go index dad45d12dda..765eb9eb479 100644 --- a/t/t.go +++ b/t/t.go @@ -1,5 +1,5 @@ /* - * Copyright 2023 Dgraph Labs, Inc. and Contributors + * Copyright 2022 Dgraph Labs, Inc. and Contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +21,7 @@ import ( "bytes" "context" "fmt" + "io/ioutil" "log" "math/rand" "os" @@ -39,7 +40,6 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" "github.com/docker/docker/client" - "github.com/golang/glog" "github.com/spf13/pflag" "golang.org/x/tools/go/packages" @@ -66,8 +66,6 @@ var ( "Only run tests for this package") runTest = pflag.StringP("test", "t", "", "Only run this test") - testType = pflag.StringP("test-type", "", "", - "Test type e.g unit,integration,upgrade") runCustom = pflag.BoolP("custom-only", "o", false, "Run only custom cluster tests.") count = pflag.IntP("count", "c", 0, @@ -170,13 +168,8 @@ func detectRace(prefix string) bool { } func outputLogs(prefix string) { - f, err := os.CreateTemp(".", prefix+"*.log") + f, err := ioutil.TempFile(".", prefix+"*.log") x.Check(err) - defer func() { - if err := f.Close(); err != nil { - fmt.Printf("error closing file: %v", err) - } - }() printLogs := func(container string) { in := testutil.GetContainerInstance(prefix, container) c := in.GetContainer() @@ -186,9 +179,7 @@ func outputLogs(prefix string) { logCmd := exec.Command("docker", "logs", c.ID) out, err := logCmd.CombinedOutput() x.Check(err) - if _, err := f.Write(out); err != nil { - fmt.Printf("error writing container logs to file: %v", err) - } + f.Write(out) fmt.Printf("Docker logs for %s is %s with error %+v ", c.ID, string(out), err) } for i := 0; i <= 3; i++ { @@ -198,6 +189,8 @@ func outputLogs(prefix string) { for i := 0; i <= 6; i++ { printLogs("alpha" + strconv.Itoa(i)) } + f.Sync() + f.Close() s := fmt.Sprintf("---> LOGS for %s written to %s .\n", prefix, f.Name()) _, err = oc.Write([]byte(s)) x.Check(err) @@ -224,29 +217,24 @@ func stopCluster(composeFile, prefix string, wg *sync.WaitGroup, err error) { tmp := fmt.Sprintf("%s.%s", tmpCoverageFile, c.ID) containerInfo, err := testutil.DockerInspect(c.ID) - if err != nil { - fmt.Printf("error while inspecting container. Prefix: %s. Error: %v\n", prefix, err) - } - workDir := containerInfo.Config.WorkingDir err = testutil.DockerCpFromContainer(c.ID, workDir+"/coverage.out", tmp) if err != nil { - fmt.Printf("error bringing down cluster. Failed at copying coverage file. Prefix: %s. Error: %v\n", + fmt.Printf("Error while bringing down cluster. Failed at copying coverage file. Prefix: %s. Error: %v\n", prefix, err) } if err = appendTestCoverageFile(tmp, coverageFile); err != nil { - fmt.Printf("error bringing down cluster. Failed at appending coverage file. Prefix: %s. Error: %v\n", - prefix, err, - ) + fmt.Printf("Error while bringing down cluster. Failed at appending coverage file. Prefix: %s. Error: %v\n", + prefix, err) } - _ = os.Remove(tmp) + os.Remove(tmp) coverageBulk := strings.Replace(composeFile, "docker-compose.yml", "coverage_bulk.out", -1) if err = appendTestCoverageFile(coverageBulk, coverageFile); err != nil { - fmt.Printf("Error bringing down cluster. Failed at appending coverage file. Prefix: %s. Error: %v\n", + fmt.Printf("Error while bringing down cluster. Failed at appending coverage file. Prefix: %s. Error: %v\n", prefix, err) } } @@ -265,7 +253,7 @@ func stopCluster(composeFile, prefix string, wg *sync.WaitGroup, err error) { } func runTestsFor(ctx context.Context, pkg, prefix string) error { - var args = []string{"go", "test", "-failfast", "-v"} + var args = []string{"go", "test", "-failfast", "-v", "-tags=integration"} if *race { args = append(args, "-timeout", "180m") // Todo: There are few race errors in tests itself. Enable this once that is fixed. @@ -277,9 +265,6 @@ func runTestsFor(ctx context.Context, pkg, prefix string) error { if *count > 0 { args = append(args, "-count="+strconv.Itoa(*count)) } - if len(*testType) > 0 { - args = append(args, "-tags="+*testType) - } if len(*runTest) > 0 { args = append(args, "-run="+*runTest) } @@ -295,7 +280,7 @@ func runTestsFor(ctx context.Context, pkg, prefix string) error { cmd.Env = append(cmd.Env, "TEST_DOCKER_PREFIX="+prefix) abs, err := filepath.Abs(*tmp) if err != nil { - return fmt.Errorf("while getting absolute path of tmp directory: %v Error: %v", *tmp, err) + return fmt.Errorf("while getting absolute path of tmp directory: %v Error: %v\n", *tmp, err) } cmd.Env = append(cmd.Env, "TEST_DATA_DIRECTORY="+abs) // Use failureCatcher. @@ -308,12 +293,12 @@ func runTestsFor(ctx context.Context, pkg, prefix string) error { time.Sleep(time.Second) } else { if err := cmd.Run(); err != nil { - return fmt.Errorf("while running command: %v, error: %v", args, err) + return fmt.Errorf("While running command: %v Error: %v", args, err) } } dur := time.Since(start).Round(time.Second) - tid, _ := ctx.Value(_threadIdKey{}).(int32) + tid, _ := ctx.Value("threadId").(int32) oc.Took(tid, pkg, dur) fmt.Printf("Ran tests for package: %s in %s\n", pkg, dur) if *runCoverage { @@ -333,7 +318,7 @@ func hasTestFiles(pkg string) bool { dir = filepath.Join(*baseDir, dir) hasTests := false - err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error { + filepath.Walk(dir, func(path string, info os.FileInfo, err error) error { if hasTests { return filepath.SkipDir } @@ -343,12 +328,9 @@ func hasTestFiles(pkg string) bool { } return nil }) - x.Check(err) return hasTests } -type _threadIdKey struct{} - var _threadId int32 func runTests(taskCh chan task, closer *z.Closer) error { @@ -394,7 +376,7 @@ func runTests(taskCh chan task, closer *z.Closer) error { defer stop() ctx := closer.Ctx() - ctx = context.WithValue(ctx, _threadIdKey{}, threadId) + ctx = context.WithValue(ctx, "threadId", threadId) for task := range taskCh { if ctx.Err() != nil { @@ -410,10 +392,7 @@ func runTests(taskCh chan task, closer *z.Closer) error { // If we only need to run custom cluster tests, then skip this one. continue } - if strings.Contains(*testType, "integration") { - start() - } - + start() if err = runTestsFor(ctx, task.pkg.ID, prefix); err != nil { // fmt.Printf("ERROR for package: %s. Err: %v\n", task.pkg.ID, err) return err @@ -451,10 +430,7 @@ func runCustomClusterTest(ctx context.Context, pkg string, wg *sync.WaitGroup) e var err error compose := composeFileFor(pkg) prefix := getClusterPrefix() - if strings.Contains(*testType, "integration") { - err = startCluster(compose, prefix) - } - + err = startCluster(compose, prefix) if err != nil { return err } @@ -516,8 +492,8 @@ func (o *outputCatcher) Write(p []byte) (n int, err error) { o.Lock() defer o.Unlock() - if bytes.Contains(p, []byte("FAIL")) || - bytes.Contains(p, []byte("TODO")) { + if bytes.Index(p, []byte("FAIL")) >= 0 || + bytes.Index(p, []byte("TODO")) >= 0 { o.failure.Write(p) } return os.Stdout.Write(p) @@ -850,6 +826,7 @@ func downloadLDBCFiles() { } wg.Wait() fmt.Printf("Downloaded %d files in %s \n", len(ldbcDataFiles), time.Since(start)) + } func createTestCoverageFile(path string) error { @@ -857,11 +834,7 @@ func createTestCoverageFile(path string) error { if err != nil { return err } - defer func() { - if err := outFile.Close(); err != nil { - glog.Warningf("error closing file: %v", err) - } - }() + defer outFile.Close() cmd := command("echo", coverageFileHeader) cmd.Stdout = outFile @@ -887,11 +860,7 @@ func isTestCoverageEmpty(path string) (bool, error) { if err != nil { return true, err } - defer func() { - if err := file.Close(); err != nil { - glog.Warningf("error closing file: %v", err) - } - }() + defer file.Close() var l int scanner := bufio.NewScanner(file) @@ -970,7 +939,7 @@ func run() error { oc.Took(0, "COMPILE", time.Since(start)) } - tmpDir, err := os.MkdirTemp("", "dgraph-test") + tmpDir, err := ioutil.TempDir("", "dgraph-test") x.Check(err) defer os.RemoveAll(tmpDir)