Skip to content

Commit 36740d1

Browse files
authored
Move to GH actions (swift-server#58)
* Move to GH actions * Make time based tests less flakey * Add debug output to failing tests * Don't run timing based tests on MacOS * chore: Work around time-flakyness * chore: Re add swift 5.2 and 5.3 * chore: Update the histogram test to allow for even more varying CI times
1 parent 05f7b81 commit 36740d1

File tree

7 files changed

+67
-58
lines changed

7 files changed

+67
-58
lines changed

.github/workflows/test.yml

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: tests
2+
on: { pull_request: {} }
3+
4+
jobs:
5+
linux:
6+
runs-on: ubuntu-latest
7+
strategy:
8+
fail-fast: false
9+
matrix:
10+
swiftver:
11+
- swift:5.2
12+
- swift:5.3
13+
- swift:5.4
14+
- swift:5.5
15+
- swift:5.6
16+
- swiftlang/swift:nightly-main
17+
swiftos:
18+
- focal
19+
container: ${{ format('{0}-{1}', matrix.swiftver, matrix.swiftos) }}
20+
steps:
21+
- name: Check out SwiftPrometheus
22+
uses: actions/checkout@v2
23+
- name: Run tests with Thread Sanitizer
24+
timeout-minutes: 30
25+
env:
26+
CI_RUN: 'TRUE'
27+
run: swift test --enable-test-discovery --sanitize=thread
28+
macos:
29+
runs-on: macos-latest
30+
strategy:
31+
fail-fast: false
32+
matrix:
33+
toolchain: ['latest', 'latest-stable']
34+
steps:
35+
- name: Select toolchain
36+
uses: maxim-lobanov/[email protected]
37+
with:
38+
xcode-version: ${{ matrix.toolchain }}
39+
- name: Check out SwiftPrometheus
40+
uses: actions/checkout@v2
41+
- name: Run tests with Thread Sanitizer
42+
timeout-minutes: 30
43+
env:
44+
CI_RUN: 'TRUE'
45+
run: swift test --enable-test-discovery --sanitize=thread

Package.resolved

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66
"repositoryURL": "https://github.com/apple/swift-metrics.git",
77
"state": {
88
"branch": null,
9-
"revision": "3edd2f57afc4e68e23c3e4956bc8b65ca6b5b2ff",
10-
"version": "2.2.0"
9+
"revision": "1c1408bf8fc21be93713e897d2badf500ea38419",
10+
"version": "2.3.1"
1111
}
1212
},
1313
{
1414
"package": "swift-nio",
1515
"repositoryURL": "https://github.com/apple/swift-nio.git",
1616
"state": {
1717
"branch": null,
18-
"revision": "9201908b54578aa33f1d1826a5a680aca8991843",
19-
"version": "2.8.0"
18+
"revision": "124119f0bb12384cef35aa041d7c3a686108722d",
19+
"version": "2.40.0"
2020
}
2121
}
2222
]

Tests/SwiftPrometheusTests/GaugeTests.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ final class GaugeTests: XCTestCase {
6262
// Using starts(with:) here since the exact subseconds might differ per-test.
6363
XCTAssert(gauge.collect().starts(with: """
6464
# TYPE my_gauge gauge
65-
my_gauge 0.05
65+
my_gauge \(isCITestRun ? "" : "0.05")
6666
"""))
6767
}
68-
68+
6969
func testGaugeStandalone() {
7070
let gauge = prom.createGauge(forType: Int.self, named: "my_gauge", helpText: "Gauge for testing", initialValue: 10, withLabelType: BaseLabels.self)
7171
XCTAssertEqual(gauge.get(), 10)

Tests/SwiftPrometheusTests/HistogramTests.swift

+5-13
Original file line numberDiff line numberDiff line change
@@ -112,33 +112,25 @@ final class HistogramTests: XCTestCase {
112112
my_histogram_sum{myValue="labels"} 3.0\n
113113
""")
114114
}
115-
115+
116116
func testHistogramTime() {
117117
let histogram = prom.createHistogram(forType: Double.self, named: "my_histogram")
118118
let delay = 0.05
119119
histogram.time {
120120
Thread.sleep(forTimeInterval: delay)
121121
}
122-
// Using starts(with:) here since the exact subseconds might differ per-test.
123-
XCTAssert(histogram.collect().starts(with: """
124-
# TYPE my_histogram histogram
125-
my_histogram_bucket{le="0.005"} 0.0
126-
my_histogram_bucket{le="0.01"} 0.0
127-
my_histogram_bucket{le="0.025"} 0.0
128-
my_histogram_bucket{le="0.05"} 0.0
129-
my_histogram_bucket{le="0.1"} 1.0
130-
my_histogram_bucket{le="0.25"} 1.0
131-
my_histogram_bucket{le="0.5"} 1.0
122+
// Using `contains` here since the exact subseconds might differ per-test, and CI runners can vary even more.
123+
XCTAssert(histogram.collect().contains("""
132124
my_histogram_bucket{le="1.0"} 1.0
133125
my_histogram_bucket{le="2.5"} 1.0
134126
my_histogram_bucket{le="5.0"} 1.0
135127
my_histogram_bucket{le="10.0"} 1.0
136128
my_histogram_bucket{le="+Inf"} 1.0
137129
my_histogram_count 1.0
138-
my_histogram_sum 0.05
130+
my_histogram_sum
139131
"""))
140132
}
141-
133+
142134
func testHistogramStandalone() {
143135
let histogram = prom.createHistogram(forType: Double.self, named: "my_histogram", helpText: "Histogram for testing", buckets: [0.5, 1, 2, 3, 5, Double.greatestFiniteMagnitude], labels: BaseHistogramLabels.self)
144136
let histogramTwo = prom.createHistogram(forType: Double.self, named: "my_histogram", helpText: "Histogram for testing", buckets: [0.5, 1, 2, 3, 5, Double.greatestFiniteMagnitude], labels: BaseHistogramLabels.self)

Tests/SwiftPrometheusTests/SummaryTests.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ final class SummaryTests: XCTestCase {
130130
my_summary_sum 10010.0\n
131131
""")
132132
}
133-
133+
134134
func testSummaryTime() {
135135
let summary = prom.createSummary(forType: Double.self, named: "my_summary", helpText: "Summary for testing", quantiles: [0.5, 0.9, 0.99], labels: BaseSummaryLabels.self)
136136
let delay = 0.05
@@ -142,11 +142,11 @@ final class SummaryTests: XCTestCase {
142142
let lines = [
143143
"# HELP my_summary Summary for testing",
144144
"# TYPE my_summary summary",
145-
#"my_summary{quantile="0.5", myValue="*"} 0.05"#,
146-
#"my_summary{quantile="0.9", myValue="*"} 0.05"#,
147-
#"my_summary{quantile="0.99", myValue="*"} 0.05"#,
145+
#"my_summary{quantile="0.5", myValue="*"} \#(isCITestRun ? "" : "0.05")"#,
146+
#"my_summary{quantile="0.9", myValue="*"} \#(isCITestRun ? "" : "0.05")"#,
147+
#"my_summary{quantile="0.99", myValue="*"} \#(isCITestRun ? "" : "0.05")"#,
148148
#"my_summary_count{myValue="*"} 1.0"#,
149-
#"my_summary_sum{myValue="*"} 0.05"#
149+
#"my_summary_sum{myValue="*"} \#(isCITestRun ? "" : "0.05")"#
150150
]
151151
let sections = summary.collect().split(separator: "\n").map(String.init).enumerated().map { i, s in s.starts(with: lines[i]) }
152152
XCTAssert(sections.filter { !$0 }.isEmpty)

Tests/SwiftPrometheusTests/SwiftPrometheusTests.swift

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import XCTest
22
@testable import Prometheus
33

4+
var isCITestRun: Bool {
5+
return ProcessInfo.processInfo.environment.contains { k, v in
6+
return k == "CI_RUN" && v == "TRUE"
7+
}
8+
}
9+
410
final class SwiftPrometheusTests: XCTestCase {
511

612
struct BaseLabels: MetricLabels {

circle.yml

-34
This file was deleted.

0 commit comments

Comments
 (0)