Try to make this test less flaky. (#13254)
This commit is contained in:
@@ -10,6 +10,7 @@ import 'package:flutter_driver/driver_extension.dart';
|
||||
|
||||
void main() {
|
||||
enableFlutterDriverExtension();
|
||||
debugPrint('Application starting...');
|
||||
runApp(new MyApp());
|
||||
}
|
||||
|
||||
@@ -40,37 +41,42 @@ Widget builds: $_widgetBuilds''';
|
||||
|
||||
Future<Null> _nextState() async {
|
||||
switch (_state) {
|
||||
case FrameState.initial:
|
||||
_widgetBuilds = 0;
|
||||
_summary = 'Producing texture frames at .5x speed...';
|
||||
_state = FrameState.slow;
|
||||
_icon = Icons.stop;
|
||||
channel.invokeMethod('start', _flutterFrameRate ~/ 2);
|
||||
break;
|
||||
case FrameState.slow:
|
||||
await channel.invokeMethod('stop');
|
||||
await _summarizeStats();
|
||||
_icon = Icons.fast_forward;
|
||||
_state = FrameState.afterSlow;
|
||||
break;
|
||||
case FrameState.afterSlow:
|
||||
_widgetBuilds = 0;
|
||||
_summary = 'Producing texture frames at 2x speed...';
|
||||
_state = FrameState.fast;
|
||||
_icon = Icons.stop;
|
||||
channel.invokeMethod('start', (_flutterFrameRate * 2).toInt());
|
||||
break;
|
||||
case FrameState.fast:
|
||||
await channel.invokeMethod('stop');
|
||||
await _summarizeStats();
|
||||
_state = FrameState.afterFast;
|
||||
_icon = Icons.replay;
|
||||
break;
|
||||
case FrameState.afterFast:
|
||||
_summary = 'Press play to start again';
|
||||
_state = FrameState.initial;
|
||||
_icon = Icons.play_arrow;
|
||||
break;
|
||||
case FrameState.initial:
|
||||
debugPrint('Starting .5x speed test...');
|
||||
_widgetBuilds = 0;
|
||||
_summary = 'Producing texture frames at .5x speed...';
|
||||
_state = FrameState.slow;
|
||||
_icon = Icons.stop;
|
||||
channel.invokeMethod('start', _flutterFrameRate ~/ 2);
|
||||
break;
|
||||
case FrameState.slow:
|
||||
debugPrint('Stopping .5x speed test...');
|
||||
await channel.invokeMethod('stop');
|
||||
await _summarizeStats();
|
||||
_icon = Icons.fast_forward;
|
||||
_state = FrameState.afterSlow;
|
||||
break;
|
||||
case FrameState.afterSlow:
|
||||
debugPrint('Starting 2x speed test...');
|
||||
_widgetBuilds = 0;
|
||||
_summary = 'Producing texture frames at 2x speed...';
|
||||
_state = FrameState.fast;
|
||||
_icon = Icons.stop;
|
||||
channel.invokeMethod('start', (_flutterFrameRate * 2).toInt());
|
||||
break;
|
||||
case FrameState.fast:
|
||||
debugPrint('Stopping 2x speed test...');
|
||||
await channel.invokeMethod('stop');
|
||||
await _summarizeStats();
|
||||
_state = FrameState.afterFast;
|
||||
_icon = Icons.replay;
|
||||
break;
|
||||
case FrameState.afterFast:
|
||||
debugPrint('Test complete.');
|
||||
_summary = 'Press play to start again';
|
||||
_state = FrameState.initial;
|
||||
_icon = Icons.play_arrow;
|
||||
break;
|
||||
}
|
||||
setState(() {});
|
||||
}
|
||||
@@ -81,26 +87,34 @@ Widget builds: $_widgetBuilds''';
|
||||
_calibrate();
|
||||
}
|
||||
|
||||
static const int calibrationTickCount = 600;
|
||||
|
||||
/// Measures Flutter's frame rate.
|
||||
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;
|
||||
int tickCount = 0;
|
||||
Ticker ticker;
|
||||
ticker = createTicker((Duration _) {
|
||||
tickCount++;
|
||||
if (tickCount == 120) {
|
||||
ticker = createTicker((Duration time) {
|
||||
tickCount += 1;
|
||||
if (tickCount == calibrationTickCount) { // about 10 seconds
|
||||
final Duration elapsed = new DateTime.now().difference(startTime);
|
||||
ticker.stop();
|
||||
ticker.dispose();
|
||||
setState(() {
|
||||
_flutterFrameRate = tickCount * 1000 / elapsed.inMilliseconds;
|
||||
debugPrint('Calibrated: frame rate ${_flutterFrameRate.toStringAsFixed(1)}fps.');
|
||||
_summary = '''
|
||||
Flutter frame rate is ${_flutterFrameRate.toStringAsFixed(1)}fps.
|
||||
Press play to produce texture frames.''';
|
||||
_icon = Icons.play_arrow;
|
||||
_state = FrameState.initial;
|
||||
});
|
||||
} else {
|
||||
if ((tickCount % (calibrationTickCount ~/ 20)) == 0)
|
||||
debugPrint('Calibrating... ${(100.0 * tickCount / calibrationTickCount).floor()}%');
|
||||
}
|
||||
});
|
||||
ticker.start();
|
||||
@@ -113,7 +127,7 @@ Press play to produce texture frames.''';
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
_widgetBuilds++;
|
||||
_widgetBuilds += 1;
|
||||
return new MaterialApp(
|
||||
home: new Scaffold(
|
||||
body: new Center(
|
||||
|
||||
Reference in New Issue
Block a user