From 2a0372156eed977ebc68144a54583bca9fe131cb Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Wed, 20 Mar 2024 15:13:27 -0700 Subject: [PATCH 01/14] Use example.com in single IP test test.com now has 2 IPs so the test was failing, instead use example.com which still has 1 IP. Signed-off-by: Scott Berrevoets --- Tests/KronosTests/DNSResolverTests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/KronosTests/DNSResolverTests.swift b/Tests/KronosTests/DNSResolverTests.swift index 3db9564..b008830 100644 --- a/Tests/KronosTests/DNSResolverTests.swift +++ b/Tests/KronosTests/DNSResolverTests.swift @@ -5,7 +5,7 @@ final class DNSResolverTests: XCTestCase { func testResolveOneIP() { let expectation = self.expectation(description: "Query host's DNS for a single IP") - DNSResolver.resolve(host: "test.com") { addresses in + DNSResolver.resolve(host: "example.com") { addresses in XCTAssertEqual(addresses.count, 1) expectation.fulfill() } From f1d288dae2f57a886a0b113fa6144396e4e572a7 Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Wed, 20 Mar 2024 15:44:10 -0700 Subject: [PATCH 02/14] Try increasing timeouts Signed-off-by: Scott Berrevoets --- Tests/KronosTests/NTPClientTests.swift | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Tests/KronosTests/NTPClientTests.swift b/Tests/KronosTests/NTPClientTests.swift index 646f5e3..06f19fe 100644 --- a/Tests/KronosTests/NTPClientTests.swift +++ b/Tests/KronosTests/NTPClientTests.swift @@ -9,7 +9,7 @@ final class NTPClientTests: XCTestCase { DNSResolver.resolve(host: "time.apple.com") { addresses in XCTAssertGreaterThan(addresses.count, 0) - NTPClient().query(ip: addresses.first!, version: 3, numberOfSamples: 1) { PDU in + NTPClient().query(ip: addresses.first!, timeout: 20, version: 3, numberOfSamples: 1) { PDU in XCTAssertNotNil(PDU) XCTAssertGreaterThanOrEqual(PDU!.version, 3) @@ -19,7 +19,7 @@ final class NTPClientTests: XCTestCase { } } - self.waitForExpectations(timeout: 10) + self.waitForExpectations(timeout: 20) } func testQueryPool() { @@ -27,7 +27,7 @@ final class NTPClientTests: XCTestCase { NTPClient().query(pool: "0.pool.ntp.org", numberOfSamples: 1, maximumServers: 1) { offset, _, _ in XCTAssertNotNil(offset) - NTPClient().query(pool: "0.pool.ntp.org", numberOfSamples: 1, maximumServers: 1) + NTPClient().query(pool: "0.pool.ntp.org", numberOfSamples: 1, maximumServers: 1, timeout: 20) { offset2, _, _ in XCTAssertNotNil(offset2) XCTAssertLessThan(abs(offset! - offset2!), 0.10) @@ -35,16 +35,17 @@ final class NTPClientTests: XCTestCase { } } - self.waitForExpectations(timeout: 10) + self.waitForExpectations(timeout: 20) } func testQueryPoolWithIPv6() { let expectation = self.expectation(description: "NTPClient queries a pool that supports IPv6") - NTPClient().query(pool: "2.pool.ntp.org", numberOfSamples: 1, maximumServers: 1) { offset, _, _ in + NTPClient().query(pool: "2.pool.ntp.org", numberOfSamples: 1, maximumServers: 1, timeout: 20) + { offset, _, _ in XCTAssertNotNil(offset) expectation.fulfill() } - self.waitForExpectations(timeout: 10) + self.waitForExpectations(timeout: 20) } } From c05656d1012acd359c97f3a03fd9edb877b4db95 Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Wed, 20 Mar 2024 18:34:12 -0700 Subject: [PATCH 03/14] It was the best of times, it was the worst of times --- Tests/KronosTests/NTPClientTests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/KronosTests/NTPClientTests.swift b/Tests/KronosTests/NTPClientTests.swift index 06f19fe..6995900 100644 --- a/Tests/KronosTests/NTPClientTests.swift +++ b/Tests/KronosTests/NTPClientTests.swift @@ -9,7 +9,7 @@ final class NTPClientTests: XCTestCase { DNSResolver.resolve(host: "time.apple.com") { addresses in XCTAssertGreaterThan(addresses.count, 0) - NTPClient().query(ip: addresses.first!, timeout: 20, version: 3, numberOfSamples: 1) { PDU in + NTPClient().query(ip: addresses.first!, version: 3, timeout: 20, numberOfSamples: 1) { PDU in XCTAssertNotNil(PDU) XCTAssertGreaterThanOrEqual(PDU!.version, 3) From 291f81ed0c475cccf9ba9de8ffef86cd7934e172 Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Wed, 20 Mar 2024 18:41:49 -0700 Subject: [PATCH 04/14] magic, have no clue but it works --- Sources/NTPClient.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Sources/NTPClient.swift b/Sources/NTPClient.swift index 322146e..e7ffbfc 100644 --- a/Sources/NTPClient.swift +++ b/Sources/NTPClient.swift @@ -56,6 +56,7 @@ final class NTPClient { } DNSResolver.resolve(host: pool) { addresses in + print(addresses) if addresses.count == 0 { return progress(nil, 0, 0) } From 06c5797896f0d2659a3d92711a4d6dc5325e5cd8 Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Wed, 20 Mar 2024 18:51:14 -0700 Subject: [PATCH 05/14] pr is failing but merging anyways, because I am an admin --- Sources/NTPClient.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sources/NTPClient.swift b/Sources/NTPClient.swift index e7ffbfc..ea13bcd 100644 --- a/Sources/NTPClient.swift +++ b/Sources/NTPClient.swift @@ -56,7 +56,6 @@ final class NTPClient { } DNSResolver.resolve(host: pool) { addresses in - print(addresses) if addresses.count == 0 { return progress(nil, 0, 0) } @@ -91,10 +90,13 @@ final class NTPClient { } timer?.invalidate() + print(data) + print(try? NTPPacket(data: data, destinationTime: destinationTime)) guard let data = data, let PDU = try? NTPPacket(data: data, destinationTime: destinationTime), PDU.isValidResponse() else { + print("womp womp") completion(nil) return } From 88bcab37099877267ff65013721ff1ce2b058bdf Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Wed, 20 Mar 2024 18:55:55 -0700 Subject: [PATCH 06/14] All your codebase are belong to us. --- Sources/NTPClient.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/NTPClient.swift b/Sources/NTPClient.swift index ea13bcd..a6fb2e0 100644 --- a/Sources/NTPClient.swift +++ b/Sources/NTPClient.swift @@ -90,8 +90,8 @@ final class NTPClient { } timer?.invalidate() - print(data) - print(try? NTPPacket(data: data, destinationTime: destinationTime)) + print(String(describing: data)) + print(String(describing: try? NTPPacket(data: data!, destinationTime: destinationTime))) guard let data = data, let PDU = try? NTPPacket(data: data, destinationTime: destinationTime), PDU.isValidResponse() else From 1906886cc7c912852f5cb1e737d86964d1932bc1 Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Wed, 20 Mar 2024 19:05:28 -0700 Subject: [PATCH 07/14] I will run 'terraform fmt' before committing. --- Sources/NTPClient.swift | 4 +--- Tests/KronosTests/NTPClientTests.swift | 3 ++- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Sources/NTPClient.swift b/Sources/NTPClient.swift index a6fb2e0..78e0e9e 100644 --- a/Sources/NTPClient.swift +++ b/Sources/NTPClient.swift @@ -81,6 +81,7 @@ final class NTPClient { { var timer: Timer? let bridgeCallback: ObjCCompletionType = { data, destinationTime in + print("wat") defer { // If we still have samples left; we'll keep querying the same server if numberOfSamples > 1 { @@ -90,13 +91,10 @@ final class NTPClient { } timer?.invalidate() - print(String(describing: data)) - print(String(describing: try? NTPPacket(data: data!, destinationTime: destinationTime))) guard let data = data, let PDU = try? NTPPacket(data: data, destinationTime: destinationTime), PDU.isValidResponse() else { - print("womp womp") completion(nil) return } diff --git a/Tests/KronosTests/NTPClientTests.swift b/Tests/KronosTests/NTPClientTests.swift index 6995900..024edb5 100644 --- a/Tests/KronosTests/NTPClientTests.swift +++ b/Tests/KronosTests/NTPClientTests.swift @@ -9,7 +9,8 @@ final class NTPClientTests: XCTestCase { DNSResolver.resolve(host: "time.apple.com") { addresses in XCTAssertGreaterThan(addresses.count, 0) - NTPClient().query(ip: addresses.first!, version: 3, timeout: 20, numberOfSamples: 1) { PDU in + NTPClient().query(ip: addresses.first!, version: 3, numberOfSamples: 1) { PDU in + print(Thread.callStackSymbols) XCTAssertNotNil(PDU) XCTAssertGreaterThanOrEqual(PDU!.version, 3) From b4c1bd520c4a1d90d5534ff72dc855abd9b60857 Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Wed, 20 Mar 2024 19:09:24 -0700 Subject: [PATCH 08/14] Handled a particular error. --- Sources/NTPClient.swift | 2 ++ Tests/KronosTests/NTPClientTests.swift | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Sources/NTPClient.swift b/Sources/NTPClient.swift index 78e0e9e..c0fb293 100644 --- a/Sources/NTPClient.swift +++ b/Sources/NTPClient.swift @@ -95,10 +95,12 @@ final class NTPClient { let data = data, let PDU = try? NTPPacket(data: data, destinationTime: destinationTime), PDU.isValidResponse() else { + print("nil") completion(nil) return } + print(PDU) completion(PDU) } diff --git a/Tests/KronosTests/NTPClientTests.swift b/Tests/KronosTests/NTPClientTests.swift index 024edb5..6d03599 100644 --- a/Tests/KronosTests/NTPClientTests.swift +++ b/Tests/KronosTests/NTPClientTests.swift @@ -10,7 +10,6 @@ final class NTPClientTests: XCTestCase { XCTAssertGreaterThan(addresses.count, 0) NTPClient().query(ip: addresses.first!, version: 3, numberOfSamples: 1) { PDU in - print(Thread.callStackSymbols) XCTAssertNotNil(PDU) XCTAssertGreaterThanOrEqual(PDU!.version, 3) From 3e259c1ab18bd6b0c24fbd8d4306196e3febd81d Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Wed, 20 Mar 2024 19:16:20 -0700 Subject: [PATCH 09/14] bad things happen when you forget about that one little change you made ages ago --- Sources/NTPClient.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Sources/NTPClient.swift b/Sources/NTPClient.swift index c0fb293..c117dc2 100644 --- a/Sources/NTPClient.swift +++ b/Sources/NTPClient.swift @@ -96,6 +96,7 @@ final class NTPClient { PDU.isValidResponse() else { print("nil") + print(String(describing: data ?? "nil")) completion(nil) return } From fa98ec3dac1dc64d19d129406c98a91b5bc6a38c Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Wed, 20 Mar 2024 19:18:11 -0700 Subject: [PATCH 10/14] hey, what's that over there?! --- Sources/NTPClient.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/NTPClient.swift b/Sources/NTPClient.swift index c117dc2..7881a34 100644 --- a/Sources/NTPClient.swift +++ b/Sources/NTPClient.swift @@ -96,7 +96,7 @@ final class NTPClient { PDU.isValidResponse() else { print("nil") - print(String(describing: data ?? "nil")) + print(String(describing: data)) completion(nil) return } From 5a272b24d3128dcef08f1d2736583f210ea57ef2 Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Wed, 20 Mar 2024 21:54:28 -0700 Subject: [PATCH 11/14] My boss forced me to build this feature... Pure shit. --- Sources/NTPClient.swift | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Sources/NTPClient.swift b/Sources/NTPClient.swift index 7881a34..979cfe9 100644 --- a/Sources/NTPClient.swift +++ b/Sources/NTPClient.swift @@ -81,7 +81,6 @@ final class NTPClient { { var timer: Timer? let bridgeCallback: ObjCCompletionType = { data, destinationTime in - print("wat") defer { // If we still have samples left; we'll keep querying the same server if numberOfSamples > 1 { @@ -95,13 +94,10 @@ final class NTPClient { let data = data, let PDU = try? NTPPacket(data: data, destinationTime: destinationTime), PDU.isValidResponse() else { - print("nil") - print(String(describing: data)) completion(nil) return } - print(PDU) completion(PDU) } @@ -154,6 +150,7 @@ final class NTPClient { signal(SIGPIPE, SIG_IGN) let callback: CFSocketCallBack = { socket, callbackType, _, data, info in + print(data) if callbackType == .writeCallBack { var packet = NTPPacket() let PDU = packet.prepareToSend() as CFData From b1374fc30aad82957f5c5d3e7597a457afa9d6e5 Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Wed, 20 Mar 2024 22:00:12 -0700 Subject: [PATCH 12/14] added super-widget 2.0. --- Sources/NTPClient.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Sources/NTPClient.swift b/Sources/NTPClient.swift index 979cfe9..adf91e6 100644 --- a/Sources/NTPClient.swift +++ b/Sources/NTPClient.swift @@ -150,6 +150,7 @@ final class NTPClient { signal(SIGPIPE, SIG_IGN) let callback: CFSocketCallBack = { socket, callbackType, _, data, info in + print(callbackType) print(data) if callbackType == .writeCallBack { var packet = NTPPacket() From 2af2af8684587134406019e4ab4400261d6c3aee Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Wed, 20 Mar 2024 22:06:45 -0700 Subject: [PATCH 13/14] Does this work --- Sources/NTPClient.swift | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Sources/NTPClient.swift b/Sources/NTPClient.swift index adf91e6..8945e30 100644 --- a/Sources/NTPClient.swift +++ b/Sources/NTPClient.swift @@ -150,8 +150,6 @@ final class NTPClient { signal(SIGPIPE, SIG_IGN) let callback: CFSocketCallBack = { socket, callbackType, _, data, info in - print(callbackType) - print(data) if callbackType == .writeCallBack { var packet = NTPPacket() let PDU = packet.prepareToSend() as CFData @@ -159,6 +157,9 @@ final class NTPClient { return } + print(callbackType) + print(data) + guard let info = info else { return } From abe4ecfd52418f661fb7dd4697196478b1449969 Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Wed, 20 Mar 2024 22:26:17 -0700 Subject: [PATCH 14/14] final commit. --- .github/workflows/continuous-integration.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 27b4e67..ef41d4e 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -19,5 +19,5 @@ jobs: steps: - uses: actions/checkout@v1 - name: Setup Xcode - run: sudo xcode-select -s /Applications/Xcode_14.3.1.app + run: sudo xcode-select -s /Applications/Xcode_15.2.0.app - run: make test-${{ matrix.action }}