Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit e206c74

Browse files
authored
Fix flaky FlutterChannelsTests, stop mocking NSObject (#41747)
I don't know why this is only flaking on arm64 Macs, but instead of mocking out `NSObject` which seems to continue to be mocked on some background thread, instead mock out the more-specific `FlutterTaskQueue` protocol. Turn the tests back on. Fixes flutter/flutter#126013 Reverts #41740 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
1 parent b370e11 commit e206c74

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

shell/platform/darwin/common/framework/Source/FlutterChannelsTest.m

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
// These tests are flaky on arm64.
6-
// TODO(dnfield): reenable after fixing https://github.com/flutter/flutter/issues/126013
7-
#if !defined(__aarch64__) && !defined(__arm64__)
8-
95
#if !__has_feature(objc_arc)
106
#error ARC must be enabled!
117
#endif
@@ -15,6 +11,9 @@
1511
#import <OCMock/OCMock.h>
1612
#import <XCTest/XCTest.h>
1713

14+
@protocol FlutterTaskQueue <NSObject>
15+
@end
16+
1817
@interface MockBinaryMessenger : NSObject <FlutterBinaryMessenger>
1918
@property(nonatomic, copy) NSString* channel;
2019
@property(nonatomic, strong) NSData* message;
@@ -218,7 +217,7 @@ - (void)testBasicMessageChannelTaskQueue {
218217
FlutterBinaryMessengerConnection connection = 123;
219218
id binaryMessenger = OCMProtocolMock(@protocol(FlutterBinaryMessenger));
220219
id codec = OCMProtocolMock(@protocol(FlutterMethodCodec));
221-
id taskQueue = OCMClassMock([NSObject class]);
220+
id taskQueue = OCMProtocolMock(@protocol(FlutterTaskQueue));
222221
FlutterBasicMessageChannel* channel =
223222
[[FlutterBasicMessageChannel alloc] initWithName:channelName
224223
binaryMessenger:binaryMessenger
@@ -246,7 +245,7 @@ - (void)testBasicMessageChannelInvokeHandlerAfterChannelReleased {
246245
FlutterBinaryMessengerConnection connection = 123;
247246
id binaryMessenger = OCMProtocolMock(@protocol(FlutterBinaryMessenger));
248247
id codec = OCMProtocolMock(@protocol(FlutterMessageCodec));
249-
id taskQueue = OCMClassMock([NSObject class]);
248+
id taskQueue = OCMProtocolMock(@protocol(FlutterTaskQueue));
250249
FlutterBasicMessageChannel* channel =
251250
[[FlutterBasicMessageChannel alloc] initWithName:channelName
252251
binaryMessenger:binaryMessenger
@@ -283,7 +282,7 @@ - (void)testMethodChannelInvokeHandlerAfterChannelReleased {
283282
@autoreleasepool {
284283
id binaryMessenger = OCMProtocolMock(@protocol(FlutterBinaryMessenger));
285284
id codec = OCMProtocolMock(@protocol(FlutterMethodCodec));
286-
id taskQueue = OCMClassMock([NSObject class]);
285+
id taskQueue = OCMProtocolMock(@protocol(FlutterTaskQueue));
287286
FlutterMethodChannel* channel = [[FlutterMethodChannel alloc] initWithName:channelName
288287
binaryMessenger:binaryMessenger
289288
codec:codec
@@ -315,7 +314,7 @@ - (void)testMethodChannelTaskQueue {
315314
FlutterBinaryMessengerConnection connection = 123;
316315
id binaryMessenger = OCMProtocolMock(@protocol(FlutterBinaryMessenger));
317316
id codec = OCMProtocolMock(@protocol(FlutterMethodCodec));
318-
id taskQueue = OCMClassMock([NSObject class]);
317+
id taskQueue = OCMProtocolMock(@protocol(FlutterTaskQueue));
319318
FlutterMethodChannel* channel = [[FlutterMethodChannel alloc] initWithName:channelName
320319
binaryMessenger:binaryMessenger
321320
codec:codec
@@ -340,7 +339,7 @@ - (void)testEventChannelTaskQueue {
340339
FlutterBinaryMessengerConnection connection = 123;
341340
id binaryMessenger = OCMProtocolMock(@protocol(FlutterBinaryMessenger));
342341
id codec = OCMProtocolMock(@protocol(FlutterMethodCodec));
343-
id taskQueue = OCMClassMock([NSObject class]);
342+
id taskQueue = OCMProtocolMock(@protocol(FlutterTaskQueue));
344343
id handler = OCMProtocolMock(@protocol(FlutterStreamHandler));
345344
FlutterEventChannel* channel = [[FlutterEventChannel alloc] initWithName:channelName
346345
binaryMessenger:binaryMessenger
@@ -360,5 +359,3 @@ - (void)testEventChannelTaskQueue {
360359
}
361360

362361
@end
363-
364-
#endif // !defined(__arch64__) && !defined(__arm64__)

0 commit comments

Comments
 (0)