Skip to content
Snippets Groups Projects
Commit 860b1da0 authored by Muxi Yan's avatar Muxi Yan
Browse files

Resume GRXBufferedPipe when it gets dealloced

parent e5cd1765
No related branches found
No related tags found
No related merge requests found
...@@ -110,4 +110,12 @@ ...@@ -110,4 +110,12 @@
self.state = GRXWriterStateFinished; self.state = GRXWriterStateFinished;
} }
- (void)dealloc {
GRXWriterState state = self.state;
if (state == GRXWriterStateNotStarted ||
state == GRXWriterStatePaused) {
dispatch_resume(_writeQueue);
}
}
@end @end
...@@ -213,4 +213,74 @@ ...@@ -213,4 +213,74 @@
XCTAssertEqualObjects(handler.errorOrNil, nil); XCTAssertEqualObjects(handler.errorOrNil, nil);
} }
#define WRITE_ROUNDS (1000)
- (void)testBufferedPipeResumeWhenDealloc {
id anyValue = @7;
id<GRXWriteable> writeable = [GRXWriteable writeableWithSingleHandler:^(id value, NSError *errorOrNil) {
}];
// Release after alloc;
GRXBufferedPipe *pipe = [GRXBufferedPipe pipe];
pipe = nil;
// Release after write but before start
pipe = [GRXBufferedPipe pipe];
for (int i = 0; i < WRITE_ROUNDS; i++) {
[pipe writeValue:anyValue];
}
pipe = nil;
// Release after start but not write
pipe = [GRXBufferedPipe pipe];
[pipe startWithWriteable:writeable];
pipe = nil;
// Release after start and write
pipe = [GRXBufferedPipe pipe];
for (int i = 0; i < WRITE_ROUNDS; i++) {
[pipe writeValue:anyValue];
}
[pipe startWithWriteable:writeable];
pipe = nil;
// Release after start, write and pause
pipe = [GRXBufferedPipe pipe];
[pipe startWithWriteable:writeable];
for (int i = 0; i < WRITE_ROUNDS; i++) {
[pipe writeValue:anyValue];
}
pipe.state = GRXWriterStatePaused;
for (int i = 0; i < WRITE_ROUNDS; i++) {
[pipe writeValue:anyValue];
}
pipe = nil;
// Release after start, write, pause and finish
pipe = [GRXBufferedPipe pipe];
[pipe startWithWriteable:writeable];
for (int i = 0; i < WRITE_ROUNDS; i++) {
[pipe writeValue:anyValue];
}
pipe.state = GRXWriterStatePaused;
for (int i = 0; i < WRITE_ROUNDS; i++) {
[pipe writeValue:anyValue];
}
[pipe finishWithError:nil];
pipe = nil;
// Release after start, write, pause, finish and resume
pipe = [GRXBufferedPipe pipe];
[pipe startWithWriteable:writeable];
for (int i = 0; i < WRITE_ROUNDS; i++) {
[pipe writeValue:anyValue];
}
pipe.state = GRXWriterStatePaused;
for (int i = 0; i < WRITE_ROUNDS; i++) {
[pipe writeValue:anyValue];
}
[pipe finishWithError:nil];
pipe.state = GRXWriterStateStarted;
pipe = nil;
}
@end @end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment