Skip to content

Commit

Permalink
Tests: adjust synchronization tests for Windows
Browse files Browse the repository at this point in the history
Windows does not support pthreads.  Adjust the tests to use the Windows
APIs for locking where the primitive being used is the `SRWLOCK`.
  • Loading branch information
compnerd committed Jun 7, 2023
1 parent 3808cd6 commit 7f930cb
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Tests/SwiftDocCTests/Utility/SynchronizationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

import XCTest
@testable import SwiftDocC
#if os(Windows)
import func WinSDK.TryAcquireSRWLockExclusive
#endif

class SynchronizationTests: XCTestCase {
func testInitialState() {
Expand All @@ -21,6 +24,8 @@ class SynchronizationTests: XCTestCase {
// Verify the lock is unlocked
#if os(macOS) || os(iOS)
XCTAssertTrue(os_unfair_lock_trylock(synced.lock))
#elseif os(Windows)
XCTAssertNotEqual(TryAcquireSRWLockExclusive(synced.lock), 0)
#else
XCTAssertEqual(pthread_mutex_trylock(synced.lock),0)
#endif
Expand All @@ -44,6 +49,8 @@ class SynchronizationTests: XCTestCase {
// Verify the lock is unlocked after running the block
#if os(macOS) || os(iOS)
XCTAssertTrue(os_unfair_lock_trylock(synced.lock))
#elseif os(Windows)
XCTAssertNotEqual(TryAcquireSRWLockExclusive(synced.lock), 0)
#else
XCTAssertEqual(pthread_mutex_trylock(synced.lock),0)
#endif
Expand All @@ -66,6 +73,8 @@ class SynchronizationTests: XCTestCase {
// Verify the used lock is lock in here
#if os(macOS) || os(iOS)
XCTAssertFalse(os_unfair_lock_trylock(synced.lock))
#elseif os(Windows)
XCTAssertEqual(TryAcquireSRWLockExclusive(synced.lock), 0)
#else
XCTAssertNotEqual(pthread_mutex_trylock(synced.lock),0)
#endif
Expand All @@ -90,6 +99,8 @@ class SynchronizationTests: XCTestCase {
// Verify that the lock is unlocked after re-throwing
#if os(macOS) || os(iOS)
XCTAssertTrue(os_unfair_lock_trylock(synced.lock))
#elseif os(Windows)
XCTAssertNotEqual(TryAcquireSRWLockExclusive(synced.lock), 0)
#else
XCTAssertEqual(pthread_mutex_trylock(synced.lock),0)
#endif
Expand Down Expand Up @@ -128,6 +139,8 @@ class SynchronizationTests: XCTestCase {
// Verify the lock is unlocked
#if os(macOS) || os(iOS)
XCTAssertTrue(os_unfair_lock_trylock(synced.lock))
#elseif os(Windows)
XCTAssertNotEqual(TryAcquireSRWLockExclusive(synced.lock), 0)
#else
XCTAssertEqual(pthread_mutex_trylock(synced.lock), 0)
#endif
Expand Down

0 comments on commit 7f930cb

Please sign in to comment.