-
Notifications
You must be signed in to change notification settings - Fork 6k
Use ShellTest::Config struct to create Shell #42332
Conversation
c747b46 to
b1ea24a
Compare
19bcecb to
0a9a584
Compare
dnfield
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this idea, the config object could be cleaned up a bit.
If assigning defaults needs more than simple logic (like perhaps the default for task_runners), consider using a builder pattern.
shell/common/shell_test.h
Outdated
| // Required. | ||
| const Settings& settings; | ||
| // Defaults to &GetTaskRunnersForFixture(). | ||
| const TaskRunners* task_runners; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't use a raw pointer here.
Just keep this as a value - avoids one more semantic change in the way these tests work, and avoids ambiguity around whether this can be nullptr and what that means.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also in general here: instead of specifying defaults in a comment, initialize the values here with a default.
|
From PR review triage: Converting to a draft. |
|
This pull request has been changed to a draft. The currently pending flutter-gold status will not be able to resolve until a new commit is pushed or the change is marked ready for review again. |
9a9e92a to
d96abce
Compare
| // Required. | ||
| const Settings& settings; | ||
| // Defaults to GetTaskRunnersForFixture(). | ||
| std::optional<TaskRunners> task_runners = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is where I think the builder could be helpful - you don't want the public interface here to actually be optional.
But if you don't want to use a builder I think we should make the std::optional be on the constructor for this struct and make the member non-optional - because otherwise callers will always have to check (and get linted against not checking now) whether the optional has a value when it really always does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not that I don't want to use a builder, but here's the idea: I can create a TaskRunnersBuilder, which has two ctors:
// implicit conversion, so that existing tests work without modification
TaskRunnersBuilder(TaskRunner);
// Defaults to GetTaskRunnersForFixture()
TaskRunnersBuilder();
But I think it's really just reinventing the wheel for std::optional because it's not semantically obvious what the default behavior is (and the doc is now hidden even deeper).
And what's worse, because this field is a value, not a pointer of a function, I can't really specify an "empty" value if not for the default ctor.
As for
because otherwise callers will always have to check (and get linted against not checking now) whether the optional has a value when it really always does
I don't think this is a problem, because this struct really is only used by ShellTest::CreateShell.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another option is to mark task_runners as mandatory so that you always explicit write GetTaskRunnersForFixture() for every call.
|
Also I created a builder for |
| ShellTestPlatformViewBuilder::ShellTestPlatformViewBuilder(Config config) | ||
| : config_(config) {} | ||
|
|
||
| std::unique_ptr<PlatformView> ShellTestPlatformViewBuilder::operator()( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: avoid defining a custom operator for this, just make a Build method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The custom operator is to make this class assignable to the current std::function parameter. We can turn this into a Build method instead, but then the several cases that currently define a custom closure will have to define a new class that takes a closure. Should I do it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shell::CreateCallback<PlatformView> platform_view_create_callback =
[task_runners, main_context](flutter::Shell& shell) {
auto result = std::make_unique<TestPlatformView>(shell, task_runners);
ON_CALL(*result, CreateRenderingSurface())
.WillByDefault(::testing::Invoke([main_context] {
auto surface = std::make_unique<MockSurface>();
ON_CALL(*surface, GetContext())
.WillByDefault(Return(main_context.get()));
ON_CALL(*surface, IsValid()).WillByDefault(Return(true));
ON_CALL(*surface, MakeRenderContextCurrent())
.WillByDefault(::testing::Invoke([] {
return std::make_unique<GLContextDefaultResult>(true);
}));
return surface;
}));
return result;
};
auto shell = CreateShell({
.settings = settings,
.task_runners = task_runners,
.platform_view_create_callback = platform_view_create_callback,
});engine/shell/common/shell_unittests.cc
Line 1608 in 6699bbb
| Shell::CreateCallback<PlatformView> platform_view_create_callback = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fine then.
dnfield
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with nit
|
auto label is removed for flutter/engine, pr: 42332, due to - The status or check suite Linux Host clang-tidy has failed. Please fix the issues identified (or deflake) before re-applying this label. |
…128669) flutter/engine@6e2c71a...5da44b9 2023-06-11 [email protected] Use ShellTest::Config struct to create Shell (flutter/engine#42332) 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 [email protected],[email protected],[email protected] 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://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
This PR refactors
ShellTest::CreateShellso that instead of taking a list of optional parameters, it takes aConfigstruct, almost all fields of which have default values. This makes calling this method cleaner, and makes it easier to add more parameters. A short version is also kept that takessettingsandtask_runners, since this version is used so often.Currently
ShellTest::CreateShell's full version has 2 mandatory parameters and 5 optional parameters. Many calls to this method have to list a long list of default parameters before going to the single one that needs overwriting, and adding new parameters to this call is even more tedious.Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.