Skip to content

Commit a0a5475

Browse files
authored
Add benchmarks for end-to-end tests and examples (#611)
* endtoend: Add benchmarks for all end-to-end tests * workflows: Run the benchmarks on master / tags
1 parent 3875006 commit a0a5475

2 files changed

Lines changed: 63 additions & 1 deletion

File tree

.github/workflows/equinox.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@ on:
99

1010
jobs:
1111

12+
benchmark:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v2
16+
- name: Set up Go 1.14
17+
uses: actions/setup-go@v2
18+
with:
19+
go-version: '1.14'
20+
- uses: equinox-io/setup@master
21+
- run: go test -bench . -json -benchmem -run=XXX ./...
22+
1223
macos:
1324
name: release --platforms darwin
1425
runs-on: macos-latest
@@ -28,7 +39,7 @@ jobs:
2839
linux:
2940
name: release --platforms linux
3041
runs-on: ubuntu-latest
31-
needs: [macos]
42+
needs: [macos, benchmark]
3243
steps:
3344
- uses: actions/checkout@v2
3445
- name: Set up Go 1.14

internal/endtoend/endtoend_test.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,30 @@ func TestExamples(t *testing.T) {
4444
}
4545
}
4646

47+
func BenchmarkExamples(b *testing.B) {
48+
examples, err := filepath.Abs(filepath.Join("..", "..", "examples"))
49+
if err != nil {
50+
b.Fatal(err)
51+
}
52+
files, err := ioutil.ReadDir(examples)
53+
if err != nil {
54+
b.Fatal(err)
55+
}
56+
for _, replay := range files {
57+
if !replay.IsDir() {
58+
continue
59+
}
60+
tc := replay.Name()
61+
b.Run(tc, func(b *testing.B) {
62+
path := filepath.Join(examples, tc)
63+
var stderr bytes.Buffer
64+
for i := 0; i < b.N; i++ {
65+
cmd.Generate(cmd.Env{}, path, &stderr)
66+
}
67+
})
68+
}
69+
}
70+
4771
func TestReplay(t *testing.T) {
4872
t.Parallel()
4973
var dirs []string
@@ -139,3 +163,30 @@ func expectedStderr(t *testing.T, dir string) string {
139163
}
140164
return ""
141165
}
166+
167+
func BenchmarkReplay(b *testing.B) {
168+
var dirs []string
169+
err := filepath.Walk("testdata", func(path string, info os.FileInfo, err error) error {
170+
if err != nil {
171+
return err
172+
}
173+
if info.Name() == "sqlc.json" || info.Name() == "sqlc.yaml" {
174+
dirs = append(dirs, filepath.Dir(path))
175+
return filepath.SkipDir
176+
}
177+
return nil
178+
})
179+
if err != nil {
180+
b.Fatal(err)
181+
}
182+
for _, replay := range dirs {
183+
tc := replay
184+
b.Run(tc, func(b *testing.B) {
185+
path, _ := filepath.Abs(tc)
186+
var stderr bytes.Buffer
187+
for i := 0; i < b.N; i++ {
188+
cmd.Generate(cmd.Env{}, path, &stderr)
189+
}
190+
})
191+
}
192+
}

0 commit comments

Comments
 (0)