-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add benchmarks for Artefact Page (#192)
* Add benchmarks for Artefact Page * add missing trailing commas
- Loading branch information
Showing
8 changed files
with
263 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,4 +24,7 @@ doc/api/ | |
*.freezed.dart | ||
*.g.dart | ||
|
||
custom_lint.log | ||
custom_lint.log | ||
|
||
# Benchmark results | ||
benchmarks/*.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:web_benchmarks/client.dart'; | ||
|
||
import 'common.dart'; | ||
|
||
class ScrollRecorder extends AppRecorder { | ||
ScrollRecorder() : super(benchmarkName: 'scrolling'); | ||
|
||
@override | ||
Future<void> start() async { | ||
final firstTestExecution = find.text('Environment 0').evaluate().first; | ||
final scrollable = Scrollable.of(firstTestExecution); | ||
|
||
while (true) { | ||
await scrollable.position.animateTo( | ||
scrollable.position.maxScrollExtent, | ||
curve: Curves.linear, | ||
duration: const Duration(seconds: 10), | ||
); | ||
await scrollable.position.animateTo( | ||
scrollable.position.minScrollExtent, | ||
curve: Curves.linear, | ||
duration: const Duration(seconds: 10), | ||
); | ||
} | ||
} | ||
} | ||
|
||
Future<void> main() async { | ||
await runBenchmarks( | ||
<String, RecorderFactory>{ | ||
'scrolling': () => ScrollRecorder(), | ||
}, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:web_benchmarks/client.dart'; | ||
|
||
import 'common.dart'; | ||
|
||
class TapRecorder extends AppRecorder { | ||
TapRecorder() : super(benchmarkName: 'tapping'); | ||
|
||
@override | ||
Future<void> start() async { | ||
final controller = LiveWidgetController(WidgetsBinding.instance); | ||
final firstTestExecution = find.text('Environment 0'); | ||
final failedSection = find.textContaining(RegExp(r'Failed \d+')); | ||
final passedSection = find.textContaining(RegExp(r'Passed \d+')); | ||
final skippedSection = find.textContaining(RegExp(r'Skipped \d+')); | ||
|
||
while (true) { | ||
await controller.tap(firstTestExecution); | ||
await controller.pumpAndSettle(); | ||
await controller.tap(failedSection); | ||
await controller.pumpAndSettle(); | ||
await controller.tap(skippedSection); | ||
await controller.pumpAndSettle(); | ||
await controller.tap(passedSection); | ||
await controller.pumpAndSettle(); | ||
await controller.tap(firstTestExecution); | ||
await controller.pumpAndSettle(); | ||
} | ||
} | ||
} | ||
|
||
Future<void> main() async { | ||
await runBenchmarks( | ||
<String, RecorderFactory>{ | ||
'tapping': () => TapRecorder(), | ||
}, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import 'package:flutter/widgets.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:mocktail/mocktail.dart'; | ||
import 'package:testcase_dashboard/app.dart'; | ||
import 'package:testcase_dashboard/models/artefact.dart'; | ||
import 'package:testcase_dashboard/models/artefact_build.dart'; | ||
import 'package:testcase_dashboard/models/environment.dart'; | ||
import 'package:testcase_dashboard/models/family_name.dart'; | ||
import 'package:testcase_dashboard/models/stage_name.dart'; | ||
import 'package:testcase_dashboard/models/test_execution.dart'; | ||
import 'package:testcase_dashboard/models/test_result.dart'; | ||
import 'package:testcase_dashboard/providers/api.dart'; | ||
import 'package:testcase_dashboard/repositories/api_repository.dart'; | ||
import 'package:web_benchmarks/client.dart'; | ||
|
||
abstract class AppRecorder extends WidgetRecorder { | ||
AppRecorder({required this.benchmarkName}) : super(name: benchmarkName); | ||
|
||
final String benchmarkName; | ||
|
||
Future<void> start(); | ||
|
||
Future<void> animationStops() async { | ||
while (WidgetsBinding.instance.hasScheduledFrame) { | ||
await Future.delayed(const Duration(milliseconds: 200)); | ||
} | ||
} | ||
|
||
@override | ||
Widget createWidget() { | ||
Future.delayed(const Duration(milliseconds: 400), start); | ||
return ProviderScope( | ||
// ignore: scoped_providers_should_specify_dependencies | ||
overrides: [apiProvider.overrideWithValue(ApiRepositoryMock())], | ||
child: const App(), | ||
); | ||
} | ||
} | ||
|
||
class ApiRepositoryMock extends Mock implements ApiRepository { | ||
@override | ||
Future<Map<int, Artefact>> getFamilyArtefacts(FamilyName family) async { | ||
const dummyArtefact = Artefact( | ||
id: 1, | ||
name: 'artefact', | ||
version: '1', | ||
track: 'latest', | ||
store: 'ubuntu', | ||
series: '', | ||
repo: '', | ||
status: ArtefactStatus.undecided, | ||
stage: StageName.beta, | ||
bugLink: '', | ||
); | ||
|
||
return { | ||
for (int i = 0; i < 100; i++) | ||
i: dummyArtefact.copyWith(id: i, name: 'artefact $i'), | ||
}; | ||
} | ||
|
||
@override | ||
Future<List<ArtefactBuild>> getArtefactBuilds(int artefactId) async { | ||
return [ | ||
ArtefactBuild( | ||
id: 1, | ||
architecture: 'amd64', | ||
revision: 1, | ||
testExecutions: [ | ||
for (int i = 0; i < 200; i++) | ||
TestExecution( | ||
id: i, | ||
ciLink: 'ciLink', | ||
c3Link: 'c3Link', | ||
status: TestExecutionStatus.failed, | ||
environment: Environment( | ||
id: i, | ||
name: 'Environment $i', | ||
architecture: 'amd64', | ||
), | ||
reviewComment: 'reviewComment', | ||
reviewDecision: [], | ||
), | ||
], | ||
), | ||
ArtefactBuild( | ||
id: 2, | ||
architecture: 'armhf', | ||
revision: 1, | ||
testExecutions: [ | ||
for (int i = 200; i < 400; i++) | ||
TestExecution( | ||
id: i, | ||
ciLink: 'ciLink', | ||
c3Link: 'c3Link', | ||
status: TestExecutionStatus.failed, | ||
environment: Environment( | ||
id: i, | ||
name: 'Environment $i', | ||
architecture: 'armhf', | ||
), | ||
reviewComment: 'reviewComment', | ||
reviewDecision: [], | ||
), | ||
], | ||
), | ||
]; | ||
} | ||
|
||
@override | ||
Future<List<TestResult>> getTestExecutionResults(int testExecutionId) async { | ||
return [ | ||
for (int i = 0; i < 300; i++) | ||
TestResult(name: 'result $i', status: TestResultStatus.passed), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import 'dart:convert' show JsonEncoder; | ||
import 'dart:io'; | ||
|
||
import 'package:web_benchmarks/server.dart'; | ||
|
||
Future<void> main(List<String> args) async { | ||
final isHeadless = args.contains('--headless'); | ||
|
||
await runBenchmarkRunnerFile( | ||
'benchmarks/artefact_page_tapping.dart', | ||
'#/snaps/0', | ||
isHeadless, | ||
); | ||
await runBenchmarkRunnerFile( | ||
'benchmarks/artefact_page_scrolling.dart', | ||
'#/snaps/0', | ||
isHeadless, | ||
); | ||
} | ||
|
||
Future<void> runBenchmarkRunnerFile( | ||
String file, | ||
String initialPage, | ||
bool isHeadless, | ||
) async { | ||
final results = await serveWebBenchmark( | ||
benchmarkAppDirectory: Directory('.'), | ||
entryPoint: file, | ||
initialPage: initialPage, | ||
headless: isHeadless, | ||
); | ||
|
||
final resultFile = File( | ||
file.replaceFirst('.dart', '_${formatDate(DateTime.now().toUtc())}.json'), | ||
); | ||
|
||
await resultFile.writeAsString( | ||
const JsonEncoder.withIndent(' ').convert(results.toJson()), | ||
); | ||
} | ||
|
||
String formatDate(DateTime date) { | ||
return '${date.year}-${date.month}-${date.day}_${date.hour}-${date.minute}-${date.second}'; | ||
} |