9
9
*/
10
10
11
11
import Basics
12
+ import Dispatch
12
13
import PackageLoading
13
14
import PackageModel
14
15
import SPMTestSupport
@@ -542,11 +543,6 @@ class PackageDescription4_2LoadingTests: PackageDescriptionLoadingTests {
542
543
}
543
544
544
545
func testCacheInvalidationOnEnv( ) throws {
545
- #if os(Linux)
546
- // rdar://79415639 (Test Case 'PackageDescription4_2LoadingTests.testCacheInvalidationOnEnv' failed)
547
- try XCTSkipIf ( true )
548
- #endif
549
-
550
546
try testWithTemporaryDirectory { path in
551
547
let fs = localFileSystem
552
548
@@ -571,15 +567,17 @@ class PackageDescription4_2LoadingTests: PackageDescriptionLoadingTests {
571
567
572
568
func check( loader: ManifestLoader , expectCached: Bool ) {
573
569
delegate. clear ( )
570
+ delegate. prepare ( expectParsing: !expectCached)
571
+
574
572
let manifest = try ! loader. load (
575
573
at: manifestPath. parentDirectory,
576
574
packageKind: . fileSystem( manifestPath. parentDirectory) ,
577
575
toolsVersion: . v4_2,
578
576
fileSystem: fs
579
577
)
580
578
581
- XCTAssertEqual ( delegate. loaded, [ manifestPath] )
582
- XCTAssertEqual ( delegate. parsed, expectCached ? [ ] : [ manifestPath] )
579
+ XCTAssertEqual ( try delegate. loaded ( timeout : . now ( ) + 1 ) , [ manifestPath] )
580
+ XCTAssertEqual ( try delegate. parsed ( timeout : . now ( ) + 1 ) , expectCached ? [ ] : [ manifestPath] )
583
581
XCTAssertEqual ( manifest. name, " Trivial " )
584
582
XCTAssertEqual ( manifest. targets [ 0 ] . name, " foo " )
585
583
}
@@ -626,15 +624,17 @@ class PackageDescription4_2LoadingTests: PackageDescriptionLoadingTests {
626
624
627
625
func check( loader: ManifestLoader , expectCached: Bool ) {
628
626
delegate. clear ( )
627
+ delegate. prepare ( expectParsing: !expectCached)
628
+
629
629
let manifest = try ! loader. load (
630
630
at: manifestPath. parentDirectory,
631
631
packageKind: . fileSystem( manifestPath. parentDirectory) ,
632
632
toolsVersion: . v4_2,
633
633
fileSystem: fs
634
634
)
635
635
636
- XCTAssertEqual ( delegate. loaded, [ manifestPath] )
637
- XCTAssertEqual ( delegate. parsed, expectCached ? [ ] : [ manifestPath] )
636
+ XCTAssertEqual ( try delegate. loaded ( timeout : . now ( ) + 1 ) , [ manifestPath] )
637
+ XCTAssertEqual ( try delegate. parsed ( timeout : . now ( ) + 1 ) , expectCached ? [ ] : [ manifestPath] )
638
638
XCTAssertEqual ( manifest. name, " Trivial " )
639
639
XCTAssertEqual ( manifest. targets [ 0 ] . name, " foo " )
640
640
}
@@ -709,18 +709,27 @@ class PackageDescription4_2LoadingTests: PackageDescriptionLoadingTests {
709
709
XCTAssertEqual ( m. name, " Trivial " )
710
710
}
711
711
712
- try check ( loader: manifestLoader)
713
- XCTAssertEqual ( delegate. loaded. count, 1 )
714
- XCTAssertEqual ( delegate. parsed. count, 1 )
712
+ do {
713
+ delegate. prepare ( )
714
+ try check ( loader: manifestLoader)
715
+ XCTAssertEqual ( try delegate. loaded ( timeout: . now( ) + 1 ) . count, 1 )
716
+ XCTAssertEqual ( try delegate. parsed ( timeout: . now( ) + 1 ) . count, 1 )
717
+ }
715
718
716
- try check ( loader: manifestLoader)
717
- XCTAssertEqual ( delegate. loaded. count, 2 )
718
- XCTAssertEqual ( delegate. parsed. count, 1 )
719
+ do {
720
+ delegate. prepare ( expectParsing: false )
721
+ try check ( loader: manifestLoader)
722
+ XCTAssertEqual ( try delegate. loaded ( timeout: . now( ) + 1 ) . count, 2 )
723
+ XCTAssertEqual ( try delegate. parsed ( timeout: . now( ) + 1 ) . count, 1 )
724
+ }
719
725
720
- stream <<< " \n \n "
721
- try check ( loader: manifestLoader)
722
- XCTAssertEqual ( delegate. loaded. count, 3 )
723
- XCTAssertEqual ( delegate. parsed. count, 2 )
726
+ do {
727
+ stream <<< " \n \n "
728
+ delegate. prepare ( )
729
+ try check ( loader: manifestLoader)
730
+ XCTAssertEqual ( try delegate. loaded ( timeout: . now( ) + 1 ) . count, 3 )
731
+ XCTAssertEqual ( try delegate. parsed ( timeout: . now( ) + 1 ) . count, 2 )
732
+ }
724
733
}
725
734
}
726
735
@@ -800,6 +809,7 @@ class PackageDescription4_2LoadingTests: PackageDescriptionLoadingTests {
800
809
let identityResolver = DefaultIdentityResolver ( )
801
810
802
811
// warm up caches
812
+ delegate. prepare ( )
803
813
let manifest = try tsc_await { manifestLoader. load ( at: manifestPath. parentDirectory,
804
814
packageIdentity: . plain( " Trivial " ) ,
805
815
packageKind: . fileSystem( manifestPath. parentDirectory) ,
@@ -818,6 +828,7 @@ class PackageDescription4_2LoadingTests: PackageDescriptionLoadingTests {
818
828
let sync = DispatchGroup ( )
819
829
for _ in 0 ..< total {
820
830
sync. enter ( )
831
+ delegate. prepare ( expectParsing: false )
821
832
manifestLoader. load ( at: manifestPath. parentDirectory,
822
833
packageIdentity: . plain( " Trivial " ) ,
823
834
packageKind: . fileSystem( manifestPath. parentDirectory) ,
@@ -845,7 +856,7 @@ class PackageDescription4_2LoadingTests: PackageDescriptionLoadingTests {
845
856
XCTFail ( " timeout " )
846
857
}
847
858
848
- XCTAssertEqual ( delegate. loaded. count, total+ 1 )
859
+ XCTAssertEqual ( try delegate. loaded ( timeout : . now ( ) + 1 ) . count, total+ 1 )
849
860
XCTAssertFalse ( observability. hasWarningDiagnostics, observability. diagnostics. description)
850
861
XCTAssertFalse ( observability. hasErrorDiagnostics, observability. diagnostics. description)
851
862
}
@@ -882,6 +893,7 @@ class PackageDescription4_2LoadingTests: PackageDescriptionLoadingTests {
882
893
}
883
894
884
895
sync. enter ( )
896
+ delegate. prepare ( )
885
897
manifestLoader. load ( at: manifestPath. parentDirectory,
886
898
packageIdentity: . plain( " Trivial- \( random) " ) ,
887
899
packageKind: . fileSystem( manifestPath. parentDirectory) ,
@@ -909,46 +921,52 @@ class PackageDescription4_2LoadingTests: PackageDescriptionLoadingTests {
909
921
XCTFail ( " timeout " )
910
922
}
911
923
912
- XCTAssertEqual ( delegate. loaded. count, total)
924
+ XCTAssertEqual ( try delegate. loaded ( timeout : . now ( ) + 1 ) . count, total)
913
925
XCTAssertFalse ( observability. hasWarningDiagnostics, observability. diagnostics. description)
914
926
XCTAssertFalse ( observability. hasErrorDiagnostics, observability. diagnostics. description)
915
927
}
916
928
}
917
929
918
930
final class ManifestTestDelegate : ManifestLoaderDelegate {
919
- private let lock = Lock ( )
920
- private var _loaded : [ AbsolutePath ] = [ ]
921
- private var _parsed : [ AbsolutePath ] = [ ]
931
+ private let loaded = ThreadSafeArrayStore < AbsolutePath > ( )
932
+ private let parsed = ThreadSafeArrayStore < AbsolutePath > ( )
933
+ private let loadingGroup = DispatchGroup ( )
934
+ private let parsingGroup = DispatchGroup ( )
922
935
923
- func willLoad( manifest: AbsolutePath ) {
924
- self . lock. withLock {
925
- self . _loaded. append ( manifest)
936
+ func prepare( expectParsing: Bool = true ) {
937
+ self . loadingGroup. enter ( )
938
+ if expectParsing {
939
+ self . parsingGroup. enter ( )
926
940
}
927
941
}
928
942
943
+ func willLoad( manifest: AbsolutePath ) {
944
+ self . loaded. append ( manifest)
945
+ self . loadingGroup. leave ( )
946
+ }
947
+
929
948
func willParse( manifest: AbsolutePath ) {
930
- self . lock. withLock {
931
- self . _parsed. append ( manifest)
932
- }
949
+ self . parsed. append ( manifest)
950
+ self . parsingGroup. leave ( )
933
951
}
934
952
935
953
func clear( ) {
936
- self . lock. withLock {
937
- self . _loaded. removeAll ( )
938
- self . _parsed. removeAll ( )
939
- }
954
+ self . loaded. clear ( )
955
+ self . parsed. clear ( )
940
956
}
941
957
942
- var loaded : [ AbsolutePath ] {
943
- self . lock . withLock {
944
- self . _loaded
958
+ func loaded( timeout : DispatchTime ) throws -> [ AbsolutePath ] {
959
+ guard case . success = self . loadingGroup . wait ( timeout : timeout ) else {
960
+ throw StringError ( " timeout waiting for loading " )
945
961
}
962
+ return self . loaded. get ( )
946
963
}
947
964
948
- var parsed : [ AbsolutePath ] {
949
- self . lock . withLock {
950
- self . _parsed
965
+ func parsed( timeout : DispatchTime ) throws -> [ AbsolutePath ] {
966
+ guard case . success = self . parsingGroup . wait ( timeout : timeout ) else {
967
+ throw StringError ( " timeout waiting for parsing " )
951
968
}
969
+ return self . parsed. get ( )
952
970
}
953
971
}
954
972
}
0 commit comments