Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[macOS] Delete FlutterCompositor tests #47527

Merged
merged 1 commit into from
Nov 1, 2023

Conversation

cbracken
Copy link
Member

@cbracken cbracken commented Oct 31, 2023

The tests for FlutterCompositor are not useful. The current tests test two things:

  1. That the mocks we set up behave the way we set them up to behave.
  2. That the implementation of FlutterCompositor is the current implementation of FlutterCompositor.

As an example, consider FlutterCompositorTest.TestPresent:

TEST(FlutterCompositorTest, TestPresent) {
__block NSArray<FlutterSurfacePresentInfo*>* presentedSurfaces = nil;
auto onPresent = ^(NSArray<FlutterSurfacePresentInfo*>* info) {
presentedSurfaces = info;
};
std::unique_ptr<flutter::FlutterCompositor> macos_compositor =
std::make_unique<FlutterCompositor>(MockViewProvider(onPresent),
/*platform_view_controller*/ nullptr);
FlutterBackingStore backing_store;
FlutterBackingStoreConfig config;
config.struct_size = sizeof(FlutterBackingStoreConfig);
config.size.width = 800;
config.size.height = 600;
macos_compositor->CreateBackingStore(&config, &backing_store);
FlutterLayer layers[] = {{
.struct_size = sizeof(FlutterLayer),
.type = kFlutterLayerContentTypeBackingStore,
.backing_store = &backing_store,
.offset = {0, 0},
.size = {800, 600},
}};
const FlutterLayer* layers_ptr = layers;
macos_compositor->Present(kFlutterImplicitViewId, &layers_ptr, 1);
ASSERT_EQ(presentedSurfaces.count, 1ul);
}

Ostensibly, this test verifies that the onPresent callback configured in our fake FlutterViewProvider implementation is called when FlutterCompositor::Present() is called.

However, taking a look at the mocking setup:

id<FlutterViewProvider> MockViewProvider(PresentBlock onPresent = nil) {
FlutterView* viewMock = OCMClassMock([FlutterView class]);
FlutterSurfaceManager* surfaceManagerMock = OCMClassMock([FlutterSurfaceManager class]);
FlutterSurface* surfaceMock = OCMClassMock([FlutterSurface class]);
__block id<MTLTexture> textureMock = OCMProtocolMock(@protocol(MTLTexture));
OCMStub([viewMock surfaceManager]).andReturn(surfaceManagerMock);
OCMStub([surfaceManagerMock surfaceForSize:CGSize{}])
.ignoringNonObjectArgs()
.andDo(^(NSInvocation* invocation) {
CGSize size;
[invocation getArgument:&size atIndex:2];
OCMStub([textureMock width]).andReturn(size.width);
OCMStub([textureMock height]).andReturn(size.height);
})
.andReturn(surfaceMock);
FlutterMetalTexture texture = {
.struct_size = sizeof(FlutterMetalTexture),
.texture_id = 1,
.texture = (__bridge void*)textureMock,
.user_data = (__bridge void*)surfaceMock,
.destruction_callback = nullptr,
};
OCMStub([surfaceManagerMock present:[OCMArg any] notify:[OCMArg any]])
.andDo(^(NSInvocation* invocation) {
NSArray<FlutterSurfacePresentInfo*>* info;
[invocation getArgument:&info atIndex:2];
if (onPresent != nil) {
onPresent(info);
}
});
OCMStub([surfaceMock asFlutterMetalTexture]).andReturn(texture);
return [[FlutterViewMockProvider alloc] initWithImplicitView:viewMock];
}

We do the following:

  1. Mock out FlutterSurfaceManager such that when a surface is requested, we hand back a mock surface. A little gross since we're relying on some knowledge of implementation details of the compositor, but let's take this as reasonable for now.
  2. We mock out FlutterSurface asFlutterMetalTexture to return a mock texture. Again, we're getting a bit deep into implementation details that the test shouldn't know about, but let's assume this gets us somewhere.
  3. We mock out FlutterSurfaceManager present:notify: to actually call the onPresent callback if it's passed in.

In effect, we're testing that:

  1. We configured our mock for FlutterSurfaceManager present:notify: to call onPresent.
  2. That FlutterCompositor::Present actually calls FlutterSurfaceManager present:notify: despite that being a simple implementation detail of that call.

This removes these tests. I have filed the following issue to track refactoring this class for testability and adding tests: flutter/flutter#137648

Encountered these tests as part of deflaking and cleaning up memory allocations throughout the macOS desktop tests.

Issue: flutter/flutter#137648
Issue: flutter/flutter#104789
Issue: flutter/flutter#127441
Issue: flutter/flutter#124840

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide and the C++, Objective-C, Java style guides.
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or the PR is test-exempt. See testing the engine for instructions on writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Copy link
Contributor

@matanlurey matanlurey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM I like this change

Copy link
Member

@goderbauer goderbauer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

The tests for FlutterCompositor are not useful. The current tests test
two things:
1. That the mocks we set up behave the way we set them up to behave.
2. That the implementation of FlutterCompositor is the current
   implementation of FlutterCompositor.

As an example, consider FlutterCompositorTest.TestPresent:
https://github.com/flutter/engine/blob/89e8de970cb99aa82e067bbdb4a8e927e53f0b28/shell/platform/darwin/macos/framework/Source/FlutterCompositorTest.mm#L107

Ostensibly, this test verifies that the onPresent callback configured in
our fake FlutterViewProvider implementation is called when
FlutterCompositor::Present() is called.

However, taking a look at the mocking setup:
https://github.com/flutter/engine/blob/89e8de970cb99aa82e067bbdb4a8e927e53f0b28/shell/platform/darwin/macos/framework/Source/FlutterCompositorTest.mm#L47-L85

We do the following:
1. Mock out FlutterSurfaceManager such that when a surface is requested,
   we hand back a mock surface. A little gross since we're relying on
   some knowledge of implementation details of the compositor, but let's
   take this as reasonable for now.
2. We mock out `FlutterSurface asFlutterMetalTexture` to return a mock
   texture. Again, we're getting a bit deep into implementation details
   that the test shouldn't know about, but let's assume this gets us
   somewhere.
3. We mock out `FlutterSurfaceManager present:notify:` to actually
   call the `onPresent` callback if it's passed in.

In effect, we're testing that:
1. We configured our mock for `FlutterSurfaceManager present:notify:` to
   call onPresent.
2. That `FlutterCompositor::Present` actually calls
   `FlutterSurfaceManager present:notify:` despite that being a simple
   implementation detail of that call.

This removes these tests. I have filed the following issue to track
refactoring this class for testability and adding tests:
flutter/flutter#137648

Encountered these tests as part of deflaking and cleaning up memory
allocations throughout the macOS desktop tests.

Issue: flutter/flutter#104789
Issue: flutter/flutter#127441
Issue: flutter/flutter#124840
@cbracken cbracken added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 31, 2023
@auto-submit auto-submit bot merged commit 2a6f1a3 into flutter:main Nov 1, 2023
26 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 1, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 1, 2023
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Nov 1, 2023
…137656)

flutter/engine@db06c2e...a0ac6b4

2023-11-01 bdero@google.com [Impeller] Include cstdint everywhere that uint32_t is used. (flutter/engine#47533)
2023-11-01 bdero@google.com [Impeller] Fix nullopt access and simplify coverage computation in GetSubpassCoverage. (flutter/engine#47347)
2023-11-01 bdero@google.com [Impeller] OpenGLES: Ensure frag/vert textures are bound with unique texture units. (flutter/engine#47218)
2023-11-01 skia-flutter-autoroll@skia.org Roll Fuchsia Linux SDK from LCfhx_lTRJI51G0zc... to _TyF0etsONe5aqCbM... (flutter/engine#47532)
2023-11-01 jonahwilliams@google.com [Impeller] stencil buffer record/replay instead of MSAA storage. (flutter/engine#47397)
2023-11-01 chris@bracken.jp [macOS] Delete FlutterCompositor tests (flutter/engine#47527)
2023-10-31 bdero@google.com [Impeller] Place Rect statics under the Rect template. (flutter/engine#47529)
2023-10-31 skia-flutter-autoroll@skia.org Roll Skia from aaa225e0cc6d to 34ef20100acc (1 revision) (flutter/engine#47530)

Also rolling transitive DEPS:
  fuchsia/sdk/core/linux-amd64 from LCfhx_lTRJI5 to _TyF0etsONe5

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-engine-flutter-autoroll
Please CC rmistry@google.com,zra@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
@cbracken cbracken deleted the remove-compositor-tests branch November 1, 2023 20:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects: desktop autosubmit Merge PR when tree becomes green via auto submit App platform-macos
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants