Try to make this test less flaky. (#13254)
This commit is contained in:
parent
c358898a76
commit
f7b2d6e773
@ -10,6 +10,7 @@ import 'package:flutter_driver/driver_extension.dart';
|
|||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
enableFlutterDriverExtension();
|
enableFlutterDriverExtension();
|
||||||
|
debugPrint('Application starting...');
|
||||||
runApp(new MyApp());
|
runApp(new MyApp());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,6 +42,7 @@ Widget builds: $_widgetBuilds''';
|
|||||||
Future<Null> _nextState() async {
|
Future<Null> _nextState() async {
|
||||||
switch (_state) {
|
switch (_state) {
|
||||||
case FrameState.initial:
|
case FrameState.initial:
|
||||||
|
debugPrint('Starting .5x speed test...');
|
||||||
_widgetBuilds = 0;
|
_widgetBuilds = 0;
|
||||||
_summary = 'Producing texture frames at .5x speed...';
|
_summary = 'Producing texture frames at .5x speed...';
|
||||||
_state = FrameState.slow;
|
_state = FrameState.slow;
|
||||||
@ -48,12 +50,14 @@ Widget builds: $_widgetBuilds''';
|
|||||||
channel.invokeMethod('start', _flutterFrameRate ~/ 2);
|
channel.invokeMethod('start', _flutterFrameRate ~/ 2);
|
||||||
break;
|
break;
|
||||||
case FrameState.slow:
|
case FrameState.slow:
|
||||||
|
debugPrint('Stopping .5x speed test...');
|
||||||
await channel.invokeMethod('stop');
|
await channel.invokeMethod('stop');
|
||||||
await _summarizeStats();
|
await _summarizeStats();
|
||||||
_icon = Icons.fast_forward;
|
_icon = Icons.fast_forward;
|
||||||
_state = FrameState.afterSlow;
|
_state = FrameState.afterSlow;
|
||||||
break;
|
break;
|
||||||
case FrameState.afterSlow:
|
case FrameState.afterSlow:
|
||||||
|
debugPrint('Starting 2x speed test...');
|
||||||
_widgetBuilds = 0;
|
_widgetBuilds = 0;
|
||||||
_summary = 'Producing texture frames at 2x speed...';
|
_summary = 'Producing texture frames at 2x speed...';
|
||||||
_state = FrameState.fast;
|
_state = FrameState.fast;
|
||||||
@ -61,12 +65,14 @@ Widget builds: $_widgetBuilds''';
|
|||||||
channel.invokeMethod('start', (_flutterFrameRate * 2).toInt());
|
channel.invokeMethod('start', (_flutterFrameRate * 2).toInt());
|
||||||
break;
|
break;
|
||||||
case FrameState.fast:
|
case FrameState.fast:
|
||||||
|
debugPrint('Stopping 2x speed test...');
|
||||||
await channel.invokeMethod('stop');
|
await channel.invokeMethod('stop');
|
||||||
await _summarizeStats();
|
await _summarizeStats();
|
||||||
_state = FrameState.afterFast;
|
_state = FrameState.afterFast;
|
||||||
_icon = Icons.replay;
|
_icon = Icons.replay;
|
||||||
break;
|
break;
|
||||||
case FrameState.afterFast:
|
case FrameState.afterFast:
|
||||||
|
debugPrint('Test complete.');
|
||||||
_summary = 'Press play to start again';
|
_summary = 'Press play to start again';
|
||||||
_state = FrameState.initial;
|
_state = FrameState.initial;
|
||||||
_icon = Icons.play_arrow;
|
_icon = Icons.play_arrow;
|
||||||
@ -81,26 +87,34 @@ Widget builds: $_widgetBuilds''';
|
|||||||
_calibrate();
|
_calibrate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const int calibrationTickCount = 600;
|
||||||
|
|
||||||
/// Measures Flutter's frame rate.
|
/// Measures Flutter's frame rate.
|
||||||
Future<Null> _calibrate() async {
|
Future<Null> _calibrate() async {
|
||||||
await new Future<Null>.delayed(const Duration(milliseconds: 200));
|
debugPrint('Awaiting calm (3 second pause)...');
|
||||||
|
await new Future<Null>.delayed(const Duration(milliseconds: 3000));
|
||||||
|
debugPrint('Calibrating...');
|
||||||
DateTime startTime;
|
DateTime startTime;
|
||||||
int tickCount = 0;
|
int tickCount = 0;
|
||||||
Ticker ticker;
|
Ticker ticker;
|
||||||
ticker = createTicker((Duration _) {
|
ticker = createTicker((Duration time) {
|
||||||
tickCount++;
|
tickCount += 1;
|
||||||
if (tickCount == 120) {
|
if (tickCount == calibrationTickCount) { // about 10 seconds
|
||||||
final Duration elapsed = new DateTime.now().difference(startTime);
|
final Duration elapsed = new DateTime.now().difference(startTime);
|
||||||
ticker.stop();
|
ticker.stop();
|
||||||
ticker.dispose();
|
ticker.dispose();
|
||||||
setState(() {
|
setState(() {
|
||||||
_flutterFrameRate = tickCount * 1000 / elapsed.inMilliseconds;
|
_flutterFrameRate = tickCount * 1000 / elapsed.inMilliseconds;
|
||||||
|
debugPrint('Calibrated: frame rate ${_flutterFrameRate.toStringAsFixed(1)}fps.');
|
||||||
_summary = '''
|
_summary = '''
|
||||||
Flutter frame rate is ${_flutterFrameRate.toStringAsFixed(1)}fps.
|
Flutter frame rate is ${_flutterFrameRate.toStringAsFixed(1)}fps.
|
||||||
Press play to produce texture frames.''';
|
Press play to produce texture frames.''';
|
||||||
_icon = Icons.play_arrow;
|
_icon = Icons.play_arrow;
|
||||||
_state = FrameState.initial;
|
_state = FrameState.initial;
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
if ((tickCount % (calibrationTickCount ~/ 20)) == 0)
|
||||||
|
debugPrint('Calibrating... ${(100.0 * tickCount / calibrationTickCount).floor()}%');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
ticker.start();
|
ticker.start();
|
||||||
@ -113,7 +127,7 @@ Press play to produce texture frames.''';
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
_widgetBuilds++;
|
_widgetBuilds += 1;
|
||||||
return new MaterialApp(
|
return new MaterialApp(
|
||||||
home: new Scaffold(
|
home: new Scaffold(
|
||||||
body: new Center(
|
body: new Center(
|
||||||
|
@ -8,7 +8,7 @@ import 'package:test/test.dart';
|
|||||||
|
|
||||||
final RegExp calibrationRegExp = new RegExp('Flutter frame rate is (.*)fps');
|
final RegExp calibrationRegExp = new RegExp('Flutter frame rate is (.*)fps');
|
||||||
final RegExp statsRegExp = new RegExp('Produced: (.*)fps\nConsumed: (.*)fps\nWidget builds: (.*)');
|
final RegExp statsRegExp = new RegExp('Produced: (.*)fps\nConsumed: (.*)fps\nWidget builds: (.*)');
|
||||||
const Duration samplingTime = const Duration(seconds: 3);
|
const Duration samplingTime = const Duration(seconds: 8);
|
||||||
|
|
||||||
Future<Null> main() async {
|
Future<Null> main() async {
|
||||||
group('texture suite', () {
|
group('texture suite', () {
|
||||||
@ -28,7 +28,7 @@ Future<Null> main() async {
|
|||||||
final SerializableFinder summary = find.byValueKey('summary');
|
final SerializableFinder summary = find.byValueKey('summary');
|
||||||
|
|
||||||
// Wait for calibration to complete and fab to appear.
|
// Wait for calibration to complete and fab to appear.
|
||||||
await driver.waitFor(fab, timeout: const Duration(seconds: 10));
|
await driver.waitFor(fab, timeout: const Duration(seconds: 40));
|
||||||
|
|
||||||
final String calibrationResult = await driver.getText(summary);
|
final String calibrationResult = await driver.getText(summary);
|
||||||
final Match matchCalibration = calibrationRegExp.matchAsPrefix(calibrationResult);
|
final Match matchCalibration = calibrationRegExp.matchAsPrefix(calibrationResult);
|
||||||
@ -58,7 +58,7 @@ Future<Null> main() async {
|
|||||||
expect(double.parse(matchFast.group(1)), closeTo(flutterFrameRate * 2.0, 5.0));
|
expect(double.parse(matchFast.group(1)), closeTo(flutterFrameRate * 2.0, 5.0));
|
||||||
expect(double.parse(matchFast.group(2)), closeTo(flutterFrameRate, 10.0));
|
expect(double.parse(matchFast.group(2)), closeTo(flutterFrameRate, 10.0));
|
||||||
expect(int.parse(matchFast.group(3)), 1);
|
expect(int.parse(matchFast.group(3)), 1);
|
||||||
});
|
}, timeout: const Timeout(const Duration(minutes: 1)));
|
||||||
|
|
||||||
tearDownAll(() async {
|
tearDownAll(() async {
|
||||||
driver?.close();
|
driver?.close();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user