Commit 3aea06b609
3aea06b609fb68adcb56f87ee1f67dc7c4fee17f
parent: 0dc8dea033
Verified · cmc
cmc <hello@cleberg.net> · 2026-11-26 12:01 UTC
Run the backlinks timing check with the gates
In the parallel suite other tests' load decided it.
Changed files (2)
Tests/OrgCoreTests/BacklinkGateTests.swift
added
+34 · view
| @@ -0,0 +1,34 @@ |
| |
1 | import Foundation |
| |
2 | import Testing |
| |
3 | @testable import OrgCore |
| |
4 | |
| |
5 | /// Timing checks for backlinks, run with the other gates (`ORGSTAR_GATES=1 swift test -c release |
| |
6 | /// --filter GateTests`) rather than in the parallel suite, where other tests' load decides them. |
| |
7 | @Suite(.enabled(if: ProcessInfo.processInfo.environment["ORGSTAR_GATES"] != nil), .serialized) |
| |
8 | struct BacklinkGateTests { |
| |
9 | let heading = Backlinks.Target(path: "/notes/a.org", title: "Fix the sink [1/2]", id: "abc-1", customID: "sink") |
| |
10 | |
| |
11 | /// The patterns are compiled once, not for each link: testing the links takes less time |
| |
12 | /// than compiling them that often would. |
| |
13 | @Test func testsManyLinksWithoutCompilingPatterns() throws { |
| |
14 | let links = (0..<4_000).map { ["id:abc-\($0)", "file:a.org::*Fix the sink", "https://example.org/\($0)", "Fix the sink"][$0 % 4] } |
| |
15 | let clock = ContinuousClock() |
| |
16 | // The fastest of several interleaved rounds, which other work on the machine can't slow. |
| |
17 | var compiling = Duration.seconds(Int64.max) |
| |
18 | var testing = Duration.seconds(Int64.max) |
| |
19 | for _ in 0..<5 { |
| |
20 | compiling = min(compiling, try clock.measure { |
| |
21 | for index in links.indices { |
| |
22 | _ = try NSRegularExpression(pattern: "(\\\\+)(?=$|[\\[\\]])") |
| |
23 | if index % 2 == 0 { _ = try Regex("^[a-zA-Z][-a-zA-Z0-9+]*:") } |
| |
24 | } |
| |
25 | }) |
| |
26 | var hits = 0 |
| |
27 | testing = min(testing, clock.measure { |
| |
28 | for link in links where Backlinks.links(link, from: "/notes/b.org", to: heading, home: "/home") { hits += 1 } |
| |
29 | }) |
| |
30 | #expect(hits == 1_000) |
| |
31 | } |
| |
32 | #expect(testing < compiling / 2, "\(testing) against \(compiling)") |
| |
33 | } |
| |
34 | } |
Tests/OrgCoreTests/BacklinkTests.swift
+2 −21 · view
| @@ -24,28 +24,9 @@ struct BacklinkTests { |
| 24 | #expect(!links("*Fix the sink", from: "/notes/b.org", to: heading)) |
24 | #expect(!links("*Fix the sink", from: "/notes/b.org", to: heading)) |
| 25 | } |
25 | } |
| 26 | |
26 | |
| 27 | /// The patterns are compiled once, not for each link: testing the links takes less time |
27 | @Test func testsManyLinks() { |
| 28 | /// than compiling them that often would. |
| |
| 29 | @Test func testsManyLinksWithoutCompilingPatterns() throws { |
| |
| 30 | let links = (0..<4_000).map { ["id:abc-\($0)", "file:a.org::*Fix the sink", "https://example.org/\($0)", "Fix the sink"][$0 % 4] } |
28 | let links = (0..<4_000).map { ["id:abc-\($0)", "file:a.org::*Fix the sink", "https://example.org/\($0)", "Fix the sink"][$0 % 4] } |
| 31 | let clock = ContinuousClock() |
29 | #expect(links.filter { Backlinks.links($0, from: "/notes/b.org", to: heading, home: "/home") }.count == 1_000) |
| 32 | // The fastest of several interleaved rounds, which other work on the machine can't slow. |
| |
| 33 | var compiling = Duration.seconds(Int64.max) |
| |
| 34 | var testing = Duration.seconds(Int64.max) |
| |
| 35 | for _ in 0..<5 { |
| |
| 36 | compiling = min(compiling, try clock.measure { |
| |
| 37 | for index in links.indices { |
| |
| 38 | _ = try NSRegularExpression(pattern: "(\\\\+)(?=$|[\\[\\]])") |
| |
| 39 | if index % 2 == 0 { _ = try Regex("^[a-zA-Z][-a-zA-Z0-9+]*:") } |
| |
| 40 | } |
| |
| 41 | }) |
| |
| 42 | var hits = 0 |
| |
| 43 | testing = min(testing, clock.measure { |
| |
| 44 | for link in links where Backlinks.links(link, from: "/notes/b.org", to: heading, home: "/home") { hits += 1 } |
| |
| 45 | }) |
| |
| 46 | #expect(hits == 1_000) |
| |
| 47 | } |
| |
| 48 | #expect(testing < compiling / 2, "\(testing) against \(compiling)") |
| |
| 49 | } |
30 | } |
| 50 | |
31 | |
| 51 | @Test func followsDenoteLinks() { |
32 | @Test func followsDenoteLinks() { |