Skip to content

Commit c2a1619

Browse files
committed
feat: add performance test for calculator and limit execution time
1 parent 6f18f90 commit c2a1619

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

.github/workflows/build.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ on:
44
push:
55
branches:
66
- master
7-
workflow_dispatch:
87

98
permissions:
109
contents: read
@@ -14,14 +13,13 @@ permissions:
1413

1514
jobs:
1615
build:
17-
if: ${{ github.event_name == 'workflow_dispatch' || contains(github.event.head_commit.message, '#build') }}
1816
uses: ./.github/workflows/build-core.yml
1917
with:
2018
run_tests: true
21-
build_macos_arm64: true
22-
build_macos_amd64: true
23-
build_windows_amd64: true
24-
build_linux_amd64: true
19+
build_macos_arm64: ${{ contains(github.event.head_commit.message, '#build') }}
20+
build_macos_amd64: ${{ contains(github.event.head_commit.message, '#build') }}
21+
build_windows_amd64: ${{ contains(github.event.head_commit.message, '#build') }}
22+
build_linux_amd64: ${{ contains(github.event.head_commit.message, '#build') }}
2523
require_macos_notarize: true
2624
require_windows_signpath: true
2725
artifact_retention_days: 10

wox.core/test/calculator_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,23 @@ func TestCalculatorTrigonometric(t *testing.T) {
149149
suite.RunQueryTests(tests)
150150
}
151151

152+
// calculator calculates should been done in < 10ms
153+
func TestCalculatorShouldHandleQuick(t *testing.T) {
154+
suite := NewTestSuite(t)
155+
setCalculatorSeparators(t, "Dot", "Comma")
156+
157+
tests := []QueryTest{
158+
{
159+
Name: "Quick calculation 1",
160+
Query: "123456789 + 987654321",
161+
ExpectedTitle: "1,111,111,110",
162+
ExpectedAction: "Copy",
163+
},
164+
}
165+
166+
suite.RunQueryTestsWithMaxDuration(tests, 10)
167+
}
168+
152169
func TestCalculatorAdvanced(t *testing.T) {
153170
suite := NewTestSuite(t)
154171
setCalculatorSeparators(t, "Dot", "Comma")

wox.core/test/test_base.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,17 @@ func (ts *TestSuite) RunQueryTests(tests []QueryTest) {
260260
}
261261
}
262262

263+
func (ts *TestSuite) RunQueryTestsWithMaxDuration(tests []QueryTest, maxDurationMs int64) {
264+
startTime := time.Now()
265+
ts.RunQueryTests(tests)
266+
elapsed := time.Since(startTime).Milliseconds()
267+
if elapsed > maxDurationMs {
268+
ts.t.Errorf("Total test duration %v exceeded maximum allowed %v", elapsed, maxDurationMs)
269+
} else {
270+
ts.t.Logf("Total test duration %v within maximum allowed %v", elapsed, maxDurationMs)
271+
}
272+
}
273+
263274
// verifyAction checks if the expected action exists in the result
264275
func (ts *TestSuite) verifyAction(result plugin.QueryResultUI, expectedAction, testName, query string) (bool, []string) {
265276
actualActions := make([]string, 0, len(result.Actions))

0 commit comments

Comments
 (0)