How to use raceDetectorSupported method of integration_test Package

Best Ginkgo code snippet using integration_test.raceDetectorSupported

Run Ginkgo automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

integration_suite_test.go

Source: integration_suite_test.go Github

copy
1package integration_test
2
3import (
4	"fmt"
5	"io"
6	"io/ioutil"
7	"os"
8	"os/exec"
9	"path/filepath"
10	"runtime"
11
12	. "github.com/onsi/ginkgo"
13	. "github.com/onsi/gomega"
14	"github.com/onsi/gomega/gexec"
15
16	"testing"
17	"time"
18)
19
20var tmpDir string
21var pathToGinkgo string
22
23func TestIntegration(t *testing.T) {
24	SetDefaultEventuallyTimeout(30 * time.Second)
25	RegisterFailHandler(Fail)
26	RunSpecs(t, "Integration Suite")
27}
28
29var _ = SynchronizedBeforeSuite(func() []byte {
30	pathToGinkgo, err := gexec.Build("../ginkgo")
31	Ω(err).ShouldNot(HaveOccurred())
32	return []byte(pathToGinkgo)
33}, func(computedPathToGinkgo []byte) {
34	pathToGinkgo = string(computedPathToGinkgo)
35})
36
37var _ = BeforeEach(func() {
38	tmpDir = fmt.Sprintf("./ginko-run-%d", GinkgoParallelNode())
39	err := os.Mkdir(tmpDir, 0700)
40	Ω(err).ShouldNot(HaveOccurred())
41})
42
43var _ = AfterEach(func() {
44	err := os.RemoveAll(tmpDir)
45	Ω(err).ShouldNot(HaveOccurred())
46})
47
48var _ = SynchronizedAfterSuite(func() {}, func() {
49	os.RemoveAll(tmpDir)
50	gexec.CleanupBuildArtifacts()
51})
52
53func tmpPath(destination string) string {
54	return filepath.Join(tmpDir, destination)
55}
56
57func fixturePath(name string) string {
58	return filepath.Join("_fixtures", name)
59}
60
61func copyIn(sourcePath, destinationPath string, recursive bool) {
62	err := os.MkdirAll(destinationPath, 0777)
63	Expect(err).NotTo(HaveOccurred())
64
65	files, err := ioutil.ReadDir(sourcePath)
66	Expect(err).NotTo(HaveOccurred())
67	for _, f := range files {
68		srcPath := filepath.Join(sourcePath, f.Name())
69		dstPath := filepath.Join(destinationPath, f.Name())
70		if f.IsDir() {
71			if recursive {
72				copyIn(srcPath, dstPath, recursive)
73			}
74			continue
75		}
76
77		src, err := os.Open(srcPath)
78
79		Expect(err).NotTo(HaveOccurred())
80		defer src.Close()
81
82		dst, err := os.Create(dstPath)
83		Expect(err).NotTo(HaveOccurred())
84		defer dst.Close()
85
86		_, err = io.Copy(dst, src)
87		Expect(err).NotTo(HaveOccurred())
88	}
89}
90
91func sameFile(filePath, otherFilePath string) bool {
92	content, readErr := ioutil.ReadFile(filePath)
93	Expect(readErr).NotTo(HaveOccurred())
94	otherContent, readErr := ioutil.ReadFile(otherFilePath)
95	Expect(readErr).NotTo(HaveOccurred())
96	Expect(string(content)).To(Equal(string(otherContent)))
97	return true
98}
99
100func sameFolder(sourcePath, destinationPath string) bool {
101	files, err := ioutil.ReadDir(sourcePath)
102	Expect(err).NotTo(HaveOccurred())
103	for _, f := range files {
104		srcPath := filepath.Join(sourcePath, f.Name())
105		dstPath := filepath.Join(destinationPath, f.Name())
106		if f.IsDir() {
107			sameFolder(srcPath, dstPath)
108			continue
109		}
110		Expect(sameFile(srcPath, dstPath)).To(BeTrue())
111	}
112	return true
113}
114
115func ginkgoCommand(dir string, args ...string) *exec.Cmd {
116	cmd := exec.Command(pathToGinkgo, args...)
117	cmd.Dir = dir
118
119	return cmd
120}
121
122func startGinkgo(dir string, args ...string) *gexec.Session {
123	cmd := ginkgoCommand(dir, args...)
124	session, err := gexec.Start(cmd, GinkgoWriter, GinkgoWriter)
125	Ω(err).ShouldNot(HaveOccurred())
126	return session
127}
128
129func removeSuccessfully(path string) {
130	err := os.RemoveAll(path)
131	Expect(err).NotTo(HaveOccurred())
132}
133
134func raceDetectorSupported() bool {
135	// https://github.com/golang/go/blob/1a370950/src/cmd/internal/sys/supported.go#L12
136	switch runtime.GOOS {
137	case "linux":
138		return runtime.GOARCH == "amd64" || runtime.GOARCH == "ppc64le" || runtime.GOARCH == "arm64"
139	case "darwin", "freebsd", "netbsd", "windows":
140		return runtime.GOARCH == "amd64"
141	default:
142		return false
143	}
144}
145
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Trigger raceDetectorSupported code on LambdaTest Cloud Grid

Execute automation tests with raceDetectorSupported on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)