diff --git a/Sources/LoggingLoki/Utility/NIOLock.swift b/Sources/LoggingLoki/Utility/NIOLock.swift index aec0b59..7b3daa8 100644 --- a/Sources/LoggingLoki/Utility/NIOLock.swift +++ b/Sources/LoggingLoki/Utility/NIOLock.swift @@ -140,20 +140,6 @@ final class LockStorage: ManagedBuffer { return storage } - @inlinable - func lock() { - self.withUnsafeMutablePointerToElements { lockPtr in - LockOperations.lock(lockPtr) - } - } - - @inlinable - func unlock() { - self.withUnsafeMutablePointerToElements { lockPtr in - LockOperations.unlock(lockPtr) - } - } - @inlinable deinit { self.withUnsafeMutablePointerToElements { lockPtr in @@ -161,13 +147,6 @@ final class LockStorage: ManagedBuffer { } } - @inlinable - func withLockPrimitive(_ body: (UnsafeMutablePointer) throws -> T) rethrows -> T { - try self.withUnsafeMutablePointerToElements { lockPtr in - return try body(lockPtr) - } - } - @inlinable func withLockedValue(_ mutate: (inout Value) throws -> T) rethrows -> T { try self.withUnsafeMutablePointers { valuePtr, lockPtr in @@ -180,75 +159,6 @@ final class LockStorage: ManagedBuffer { extension LockStorage: @unchecked Sendable { } -/// A threading lock based on `libpthread` instead of `libdispatch`. -/// -/// - note: ``NIOLock`` has reference semantics. -/// -/// This object provides a lock on top of a single `pthread_mutex_t`. This kind -/// of lock is safe to use with `libpthread`-based threading models, such as the -/// one used by NIO. On Windows, the lock is based on the substantially similar -/// `SRWLOCK` type. -@usableFromInline -struct NIOLock { - @usableFromInline - internal let _storage: LockStorage - - /// Create a new lock. - @inlinable - init() { - self._storage = .create(value: ()) - } - - /// Acquire the lock. - /// - /// Whenever possible, consider using `withLock` instead of this method and - /// `unlock`, to simplify lock handling. - @inlinable - func lock() { - self._storage.lock() - } - - /// Release the lock. - /// - /// Whenever possible, consider using `withLock` instead of this method and - /// `lock`, to simplify lock handling. - @inlinable - func unlock() { - self._storage.unlock() - } - - @inlinable - internal func withLockPrimitive(_ body: (UnsafeMutablePointer) throws -> T) rethrows -> T { - return try self._storage.withLockPrimitive(body) - } -} - -extension NIOLock { - /// Acquire the lock for the duration of the given block. - /// - /// This convenience method should be preferred to `lock` and `unlock` in - /// most situations, as it ensures that the lock will be released regardless - /// of how `body` exits. - /// - /// - Parameter body: The block to execute while holding the lock. - /// - Returns: The value returned by the block. - @inlinable - func withLock(_ body: () throws -> T) rethrows -> T { - self.lock() - defer { - self.unlock() - } - return try body() - } - - @inlinable - func withLockVoid(_ body: () throws -> Void) rethrows -> Void { - try self.withLock(body) - } -} - -extension NIOLock: Sendable {} - extension UnsafeMutablePointer { @inlinable func assertValidAlignment() { diff --git a/Sources/LoggingLoki/Utility/Timeout.swift b/Sources/LoggingLoki/Utility/Timeout.swift index c944a2c..39d2367 100644 --- a/Sources/LoggingLoki/Utility/Timeout.swift +++ b/Sources/LoggingLoki/Utility/Timeout.swift @@ -15,11 +15,3 @@ func withTimeout( return result } } - -func withTimeout( - _ timeout: Duration, - priority: TaskPriority? = nil, - operation: @escaping @Sendable () async throws -> ChildTaskResult -) async rethrows -> ChildTaskResult where ChildTaskResult: Sendable { - try await withTimeout(timeout, priority: priority, clock: ContinuousClock(), operation: operation) -} diff --git a/Tests/LoggingLokiTests/LokiLogProcessorConfigurationTests.swift b/Tests/LoggingLokiTests/LokiLogProcessorConfigurationTests.swift new file mode 100644 index 0000000..f7b9f6c --- /dev/null +++ b/Tests/LoggingLokiTests/LokiLogProcessorConfigurationTests.swift @@ -0,0 +1,15 @@ +import XCTest +@testable import LoggingLoki + +final class LokiLogProcessorConfigurationTests: XCTestCase { + func testLokiURLConstruction() { + var configuration1 = LokiLogProcessorConfiguration(lokiURL: "http://localhost:3100") + XCTAssertEqual(configuration1._lokiURL, "http://localhost:3100/loki/api/v1/push") + configuration1.lokiURL = "http://localhost:3200/" + XCTAssertEqual(configuration1._lokiURL, "http://localhost:3200/loki/api/v1/push") + configuration1.lokiURL = "http://localhost:3300" + XCTAssertEqual(configuration1._lokiURL, "http://localhost:3300/loki/api/v1/push") + var configuration2 = LokiLogProcessorConfiguration(lokiURL: "http://localhost:3100/") + XCTAssertEqual(configuration2._lokiURL, "http://localhost:3100/loki/api/v1/push") + } +}