16
16
#import < XCTest/XCTest.h>
17
17
18
18
#import " Crashlytics/Crashlytics/Components/FIRCLSContext.h"
19
+ #include " Crashlytics/Crashlytics/Components/FIRCLSGlobals.h"
19
20
#import " Crashlytics/Crashlytics/Controllers/FIRCLSRolloutsPersistenceManager.h"
20
21
#import " Crashlytics/Crashlytics/Models/FIRCLSInternalReport.h"
21
22
#import " Crashlytics/UnitTests/Mocks/FIRCLSTempMockFileManager.h"
@@ -51,6 +52,9 @@ - (void)tearDown {
51
52
}
52
53
53
54
- (void )testUpdateRolloutsStateToPersistenceWithRollouts {
55
+ XCTestExpectation *expectation = [[XCTestExpectation alloc ]
56
+ initWithDescription: @" Expect updating rollouts to finish writing." ];
57
+
54
58
NSString *encodedStateString =
55
59
@" {rollouts:[{\" parameter_key\" :\" 6d795f66656174757265\" ,\" parameter_value\" :"
56
60
@" \" e8bf99e698af7468656d6973e79a84e6b58be8af95e695b0e68daeefbc8ce8be93e585a5e4b8ade69687\" ,"
@@ -64,7 +68,43 @@ - (void)testUpdateRolloutsStateToPersistenceWithRollouts {
64
68
65
69
[self .rolloutsPersistenceManager updateRolloutsStateToPersistenceWithRollouts: data
66
70
reportID: reportId];
71
+
72
+ // Wait for the logging queue to finish.
73
+ dispatch_async (FIRCLSGetLoggingQueue (), ^{
74
+ [expectation fulfill ];
75
+ });
76
+
77
+ [self waitForExpectations: @[ expectation ] timeout: 3 ];
78
+
67
79
XCTAssertTrue ([[NSFileManager defaultManager ] fileExistsAtPath: rolloutsFilePath]);
68
80
}
69
81
82
+ - (void )testUpdateRolloutsStateToPersistenceEnsureNoHang {
83
+ dispatch_queue_t testQueue = dispatch_queue_create (" TestQueue" , DISPATCH_QUEUE_SERIAL);
84
+ XCTestExpectation *expectation =
85
+ [[XCTestExpectation alloc ] initWithDescription: @" Expect updating rollouts to return." ];
86
+ NSString *encodedStateString =
87
+ @" {rollouts:[{\" parameter_key\" :\" 6d795f66656174757265\" ,\" parameter_value\" :"
88
+ @" \" e8bf99e698af7468656d6973e79a84e6b58be8af95e695b0e68daeefbc8ce8be93e585a5e4b8ade69687\" ,"
89
+ @" \" rollout_id\" :\" 726f6c6c6f75745f31\" ,\" template_version\" :1,\" variant_id\" :"
90
+ @" \" 636f6e74726f6c\" }]}" ;
91
+
92
+ NSData *data = [encodedStateString dataUsingEncoding: NSUTF8StringEncoding];
93
+
94
+ // Clog up the queue with a long running operation. This sleep time
95
+ // must be longer than the expectation timeout.
96
+ dispatch_async (FIRCLSGetLoggingQueue (), ^{
97
+ sleep (10 );
98
+ });
99
+
100
+ dispatch_async (testQueue, ^{
101
+ // Ensure that calling this returns quickly so we don't hang
102
+ [self .rolloutsPersistenceManager updateRolloutsStateToPersistenceWithRollouts: data
103
+ reportID: reportId];
104
+ [expectation fulfill ];
105
+ });
106
+
107
+ [self waitForExpectations: @[ expectation ] timeout: 3 ];
108
+ }
109
+
70
110
@end
0 commit comments