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

[web] enable CanvasKit tests using a local bundle fetched from CIPD #92134

Merged
merged 1 commit into from
Oct 21, 2021

Conversation

yjbanov
Copy link
Contributor

@yjbanov yjbanov commented Oct 19, 2021

  • Fetch CanvasKit from CIPD to the Flutter SDK cache.
  • Copy CanvasKit files to build/web/canvaskit during flutter build web.
  • Use the local CanvasKit copy (instead of unpkg.com) when running unit-tests.
  • Add test shards that run currently passing tests in CanvasKit mode (which is the vast majority).
  • Golden tests use the ("WebRenderer": "canvaskit") key/value pair to distinguish the goldens from the HTML ones.

Fixes #71604
Fixes #70101

@flutter-dashboard flutter-dashboard bot added a: tests "flutter test", flutter_test, or one of our tests framework flutter/packages/flutter repository. See also f: labels. team Infra upgrades, team productivity, code health, technical debt. See also team: labels. tool Affects the "flutter" command-line tool. See also t: labels. labels Oct 19, 2021
@google-cla google-cla bot added the cla: yes label Oct 19, 2021
@yjbanov yjbanov force-pushed the ck-tests branch 3 times, most recently from e5a82ca to 371987b Compare October 19, 2021 23:49
@yjbanov yjbanov marked this pull request as ready for review October 20, 2021 19:52
@@ -1430,8 +1497,7 @@ Future<void> _runFlutterWebTest(String workingDirectory, List<String> tests) asy
'--concurrency=1', // do not parallelize on Cirrus, to reduce flakiness
'-v',
'--platform=chrome',
// TODO(ferhatb): Run web tests with both rendering backends.
'--web-renderer=html', // use html backend for web tests.
'--web-renderer=$webRenderer', // use html backend for web tests.
Copy link
Member

Choose a reason for hiding this comment

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

nit: update comment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor

@CaseyHillers CaseyHillers left a comment

Choose a reason for hiding this comment

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

.ci.yaml lgtm

{"dependency": "goldctl"}
]
shard: web_canvaskit_tests
subshard: "0"
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the reasoning for these being strings instead of numbers?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Technically all subshard names are strings, but some shards have a custom convention. Web shards use the numeric convention that uses subshard number ("0", "1", etc) for all subshards except the last one, which uses "_last" suffix (e.g. 7_last).

Having said that I totally botched the convention and now I fixed it. Unfortunately, because .ci.yaml changes do not take effect immediately it's easy to make mistakes like that..

@@ -365,6 +389,37 @@ class FlutterWebPlatform extends PlatformPlugin {
}
}

/// Serves a local build of CanvasKit, replacing the CDN build, which can
Copy link
Member

Choose a reason for hiding this comment

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

nice!

@@ -637,7 +637,7 @@ void main() {
environment.outputDir.childDirectory('a').childFile('a.txt')
..createSync(recursive: true)
..writeAsStringSync('A');
await const WebServiceWorker().build(environment);
await WebServiceWorker(globals.fs).build(environment);
Copy link
Member

@christopherfujino christopherfujino Oct 20, 2021

Choose a reason for hiding this comment

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

Avoid adding new calls to globals in tests. I suggest doing something like:

for (final FileSystemStyle style in <FileSystemStyle>[FileSystemStyle.posix, FileSystemStyle.windows]) {
  test('WebServiceWorker generates a service_worker for a web resource folder for ${style == FileSystemStyle.posix ? 'posix' : 'windows'}', () {
    final FileSystem fileSystem = MemoryFileSystem(style: style);
    ...
  });
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After an offline discussion, reverted to globals.fs. The test is using TestBed and Environment which are setup to use globals.fs. This file overall needs a separate clean-ups to stop depending on globals.

@@ -637,7 +637,7 @@ void main() {
environment.outputDir.childDirectory('a').childFile('a.txt')
..createSync(recursive: true)
..writeAsStringSync('A');
await const WebServiceWorker().build(environment);
await WebServiceWorker(globals.fs).build(environment);
Copy link
Member

Choose a reason for hiding this comment

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

avoid adding globals to tests

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Member

@christopherfujino christopherfujino left a comment

Choose a reason for hiding this comment

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

Some nits about the tests, but otherwise the tools change LGTM

Copy link
Contributor

@keyonghan keyonghan left a comment

Choose a reason for hiding this comment

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

LGTM with test ownership.

Copy link
Contributor

@Piinks Piinks left a comment

Choose a reason for hiding this comment

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

Should the test shards that are being added show up in CI here? They do not appear to be listed as checks, and without running them, Gold is not seeing this new info.

Copy link
Contributor

@Piinks Piinks left a comment

Choose a reason for hiding this comment

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

According to https://flutter-gold.skia.org/search?crs=github&issue=92134&patchsets=1&positive=true
these are the only builds that are sending info to Gold:

  • Windows framework_tests_widgets
  • Windows framework_tests_libraries
  • Linux web_tests_5
  • Linux web_tests_4
  • Linux web_tests_3
  • Linux web_tests_2
  • Mac framework_tests_widgets
  • Linux web_tests_1
  • Linux web_tests_7_last
  • Linux web_tests_6
  • Linux framework_tests_widgets
  • Linux web_tests_0
  • Linux framework_tests_libraries
  • Mac framework_tests_libraries

@yjbanov
Copy link
Contributor Author

yjbanov commented Oct 20, 2021

@Piinks good question. Unfortunately, the new shards do not show up right away. More details here, but the tl;dr is that new test shards are added as bringup: true and submitted. They take time to propagate to LUCI and start running without failing the build. Once we confirm that everything is working (perhaps with follow-up fixes), then we can make them build blocking.

1 similar comment
@yjbanov
Copy link
Contributor Author

yjbanov commented Oct 20, 2021

@Piinks good question. Unfortunately, the new shards do not show up right away. More details here, but the tl;dr is that new test shards are added as bringup: true and submitted. They take time to propagate to LUCI and start running without failing the build. Once we confirm that everything is working (perhaps with follow-up fixes), then we can make them build blocking.

@yjbanov
Copy link
Contributor Author

yjbanov commented Oct 20, 2021

(sorry for duplicate posts; Github is giving me errors when I post but is actually posting my comments)

@Piinks
Copy link
Contributor

Piinks commented Oct 20, 2021

Ah I see, ok! In that case it sounds like we would validate later that Gold is receiving the data correctly. Would that testing happen in post submit then? Currently the Gold flow checks images in during presubmit. It may cause some issues temporarily if these are run in post submit first, not sure though since we haven't done that before. 🙃

@yjbanov
Copy link
Contributor Author

yjbanov commented Oct 20, 2021

Ah I see, ok! In that case it sounds like we would validate later that Gold is receiving the data correctly. Would that testing happen in post submit then? Currently the Gold flow checks images in during presubmit. It may cause some issues temporarily if these are run in post submit first, not sure though since we haven't done that before. upside_down_face

Oh no! Catch-22. @CaseyHillers save us!

@CaseyHillers
Copy link
Contributor

Oh no! Catch-22. @CaseyHillers save us!

@Piinks if we're not running in presubmit, I don't think there would be a way for gold to block PRs. This should be safe to land. If there's a breakage, that's a bug and we'll need to fix the process to adhere with the tree's flaky test policy.

Comment on lines 860 to 866
Future<void> _runWebHtmlUnitTests() async {
await _runWebUnitTests('html');
}

Future<void> _runWebCanvasKitUnitTests() async {
await _runWebUnitTests('canvaskit');
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion: There's no need for async/await here.

Suggested change
Future<void> _runWebHtmlUnitTests() async {
await _runWebUnitTests('html');
}
Future<void> _runWebCanvasKitUnitTests() async {
await _runWebUnitTests('canvaskit');
}
Future<void> _runWebHtmlUnitTests() {
return _runWebUnitTests('html');
}
Future<void> _runWebCanvasKitUnitTests() {
return _runWebUnitTests('canvaskit');
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

final Directory canvasKitDirectory = flutterWebSdk.childDirectory('canvaskit');
for (final File file in canvasKitDirectory.listSync(recursive: true).whereType<File>()) {
final String relativePath = fileSystem.path.relative(file.path, from: canvasKitDirectory.path);
final String targetPath = fileSystem.path.join(environment.outputDir.path, 'canvaskit', relativePath);
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious, why not:

final File target = environment.outputDir.childDirectory('canvaskit').childFile(relativePath);
await file.copy(target.path);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

childFile takes a basename, not a sub-path.

// TODO(yjbanov): https://github.com/flutter/flutter/issues/52588
//
// Update this when we start building CanvasKit from sources. In the
// meantime, get the Web SDK directory directory from cache rather than
Copy link
Contributor

Choose a reason for hiding this comment

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

s/directory directory/directory

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@Piinks
Copy link
Contributor

Piinks commented Oct 21, 2021

@Piinks if we're not running in presubmit, I don't think there would be a way for gold to block PRs. This should be safe to land. If there's a breakage, that's a bug and we'll need to fix the process to adhere with the tree's flaky test policy.

SGTM!

Copy link
Contributor

@Piinks Piinks left a comment

Choose a reason for hiding this comment

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

LGTM - Gold changes look fine, but will need to confirm and triage all of the images with the new key set once these shards are actually running.

@yjbanov
Copy link
Contributor Author

yjbanov commented Oct 21, 2021

LGTM - Gold changes look fine, but will need to confirm and triage all of the images with the new key set once these shards are actually running.

Thanks! I might need some handholding to see it through. Might need help from you, @Piinks, and from @CaseyHillers.

@abelokon0711
Copy link

Could you explain me please how exactly does this solve #70101?

@P-B1101
Copy link

P-B1101 commented Jul 2, 2022

I think this command will use bundled canvaskit from your build folder.
flutter build web --dart-define=FLUTTER_WEB_CANVASKIT_URL=/canvaskit/
I test it using IIS from my localhost and it's worked. I think it will work on any other host too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: tests "flutter test", flutter_test, or one of our tests framework flutter/packages/flutter repository. See also f: labels. team Infra upgrades, team productivity, code health, technical debt. See also team: labels. tool Affects the "flutter" command-line tool. See also t: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Most canvaskit framework tests are failing [web] support bundling CanvasKit instead of CDN
8 participants