55// Created by Brandon Sneed on 11/4/21.
66//
77
8+ #if !os(Linux) && !os(tvOS) && !os(watchOS)
9+
810import XCTest
911@testable import Segment
1012
1113class StressTests : XCTestCase {
1214
1315 override func setUpWithError( ) throws {
1416 // Put setup code here. This method is called before the invocation of each test method in the class.
17+ RestrictedHTTPSession . reset ( )
1518 }
1619
1720 override func tearDownWithError( ) throws {
1821 // Put teardown code here. This method is called after the invocation of each test method in the class.
1922 }
2023
2124 // Linux doesn't know what URLProtocol is and on tvOS/watchOS it somehow works differently and isn't hit.
22- #if !os(Linux) && !os(tvOS) && !os(watchOS)
2325 func testDirectoryStorageStress2( ) throws {
2426 // register our network blocker
2527 guard URLProtocol . registerClass ( BlockNetworkCalls . self) else { XCTFail ( ) ; return }
2628
27- let analytics = Analytics ( configuration: Configuration ( writeKey: " stressTest2 " ) . errorHandler ( { error in
28- XCTFail ( " Storage Error: \( error) " )
29- } ) )
29+ let analytics = Analytics ( configuration: Configuration ( writeKey: " stressTest2 " )
30+ . errorHandler ( { error in
31+ XCTFail ( " Storage Error: \( error) " )
32+ } )
33+ . httpSession ( RestrictedHTTPSession ( ) )
34+ )
35+
3036 analytics. purgeStorage ( )
3137 analytics. storage. hardReset ( doYouKnowHowToUseThis: true )
3238
@@ -41,20 +47,6 @@ class StressTests: XCTestCase {
4147
4248 waitUntilStarted ( analytics: analytics)
4349
44- // set the httpclient to use our blocker session
45- let segment = analytics. find ( pluginType: SegmentDestination . self)
46- let configuration = URLSessionConfiguration . ephemeral
47- configuration. allowsCellularAccess = true
48- configuration. timeoutIntervalForResource = 30
49- configuration. timeoutIntervalForRequest = 60
50- configuration. httpMaximumConnectionsPerHost = 2
51- configuration. protocolClasses = [ BlockNetworkCalls . self]
52- configuration. httpAdditionalHeaders = [ " Content-Type " : " application/json; charset=utf-8 " ,
53- " Authorization " : " Basic test " ,
54- " User-Agent " : " analytics-ios/ \( Analytics . version ( ) ) " ]
55- let blockSession = URLSession ( configuration: configuration, delegate: nil , delegateQueue: nil )
56- segment? . httpClient? . session = blockSession
57-
5850 @Atomic var ready = false
5951 var queues = [ DispatchQueue] ( )
6052 for i in 0 ..< 30 {
@@ -110,9 +102,12 @@ class StressTests: XCTestCase {
110102 // register our network blocker
111103 guard URLProtocol . registerClass ( BlockNetworkCalls . self) else { XCTFail ( ) ; return }
112104
113- let analytics = Analytics ( configuration: Configuration ( writeKey: " stressTest " ) . errorHandler ( { error in
114- XCTFail ( " Storage Error: \( error) " )
115- } ) )
105+ let analytics = Analytics ( configuration: Configuration ( writeKey: " stressTest2 " )
106+ . errorHandler ( { error in
107+ XCTFail ( " Storage Error: \( error) " )
108+ } )
109+ . httpSession ( RestrictedHTTPSession ( ) )
110+ )
116111 analytics. storage. hardReset ( doYouKnowHowToUseThis: true )
117112
118113 DirectoryStore . fileValidator = { url in
@@ -126,20 +121,6 @@ class StressTests: XCTestCase {
126121
127122 waitUntilStarted ( analytics: analytics)
128123
129- // set the httpclient to use our blocker session
130- let segment = analytics. find ( pluginType: SegmentDestination . self)
131- let configuration = URLSessionConfiguration . ephemeral
132- configuration. allowsCellularAccess = true
133- configuration. timeoutIntervalForResource = 30
134- configuration. timeoutIntervalForRequest = 60
135- configuration. httpMaximumConnectionsPerHost = 2
136- configuration. protocolClasses = [ BlockNetworkCalls . self]
137- configuration. httpAdditionalHeaders = [ " Content-Type " : " application/json; charset=utf-8 " ,
138- " Authorization " : " Basic test " ,
139- " User-Agent " : " analytics-ios/ \( Analytics . version ( ) ) " ]
140- let blockSession = URLSession ( configuration: configuration, delegate: nil , delegateQueue: nil )
141- segment? . httpClient? . session = blockSession
142-
143124 let writeQueue1 = DispatchQueue ( label: " write queue 1 " , attributes: . concurrent)
144125 let writeQueue2 = DispatchQueue ( label: " write queue 2 " , attributes: . concurrent)
145126 let writeQueue3 = DispatchQueue ( label: " write queue 3 " , attributes: . concurrent)
@@ -317,5 +298,6 @@ class StressTests: XCTestCase {
317298 RunLoop . main. run ( until: Date . distantPast)
318299 }
319300 }
320- #endif
321301}
302+
303+ #endif
0 commit comments