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

[flutter_tools] add shuffle to hermetic run_tests #105462

Merged
merged 5 commits into from
Jun 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@

// @dart = 2.8

// TODO(gspencergoog): Remove this tag once this test's state leaks/test
// dependencies have been fixed.
// https://github.com/flutter/flutter/issues/85160
// Fails with "flutter test --test-randomize-ordering-seed=1000"
@Tags(<String>['no-shuffle'])

import 'dart:async';

import 'package:file/file.dart';
Expand Down Expand Up @@ -405,7 +399,6 @@ void main() {
Usage: () => usage,
});


testUsingContext('passes device target platform to usage', () async {
final RunCommand command = RunCommand();
final FakeDevice mockDevice = FakeDevice(sdkNameAndVersion: 'iOS 13')
Expand All @@ -431,7 +424,7 @@ void main() {
expect(usage.commands, contains(
TestUsageCommand('run', parameters: CustomDimensions.fromMap(<String, String>{
'cd3': 'false', 'cd4': 'ios', 'cd22': 'iOS 13',
'cd23': 'debug', 'cd18': 'false', 'cd15': 'swift', 'cd31': 'false',
'cd23': 'debug', 'cd18': 'false', 'cd15': 'swift', 'cd31': 'true',
Copy link
Member Author

Choose a reason for hiding this comment

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

cd31 is commandHasTerminal (https://github.com/christopherfujino/flutter/blob/improve-run-test/packages/flutter_tools/lib/src/reporting/custom_dimensions.dart#L102). The global environment was leaking into this test previously; thus, this test was passing on CI, since the Dart VM did not have a terminal attached, yet failing locally since it did. By overriding the context with a FakeStdio that defaults to hasTerminal = true, this dimension should be true both locally and on CI.

'cd56': 'false',
})
)));
Expand All @@ -441,6 +434,7 @@ void main() {
DeviceManager: () => mockDeviceManager,
FileSystem: () => fs,
ProcessManager: () => FakeProcessManager.any(),
Stdio: () => FakeStdio(),
Usage: () => usage,
});

Expand Down
44 changes: 40 additions & 4 deletions packages/flutter_tools/test/src/fakes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,9 @@ class MemoryStdout extends MemoryIOSink implements io.Stdout {

/// A Stdio that collects stdout and supports simulated stdin.
class FakeStdio extends Stdio {
final MemoryStdout _stdout = MemoryStdout();
final MemoryStdout _stdout = MemoryStdout()..terminalColumns = 80;
final MemoryIOSink _stderr = MemoryIOSink();
final StreamController<List<int>> _stdin = StreamController<List<int>>();
final FakeStdin _stdin = FakeStdin();
Copy link
Member Author

Choose a reason for hiding this comment

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


@override
MemoryStdout get stdout => _stdout;
Expand All @@ -233,16 +233,52 @@ class FakeStdio extends Stdio {
MemoryIOSink get stderr => _stderr;

@override
Stream<List<int>> get stdin => _stdin.stream;
Stream<List<int>> get stdin => _stdin;

void simulateStdin(String line) {
_stdin.add(utf8.encode('$line\n'));
_stdin.controller.add(utf8.encode('$line\n'));
}

@override
bool hasTerminal = true;

List<String> get writtenToStdout => _stdout.writes.map<String>(_stdout.encoding.decode).toList();
List<String> get writtenToStderr => _stderr.writes.map<String>(_stderr.encoding.decode).toList();
}

class FakeStdin extends Fake implements Stdin {
final StreamController<List<int>> controller = StreamController<List<int>>();

@override
bool echoMode = true;

@override
bool echoNewlineMode = true;

@override
bool lineMode = true;

@override
Stream<S> transform<S>(StreamTransformer<List<int>, S> transformer) {
return controller.stream.transform(transformer);
}

@override
StreamSubscription<List<int>> listen(
void Function(List<int> event)? onData, {
Function? onError,
void Function()? onDone,
bool? cancelOnError,
}) {
return controller.stream.listen(
onData,
onError: onError,
onDone: onDone,
cancelOnError: cancelOnError,
);
}
}

class FakePlistParser implements PlistParser {
FakePlistParser([Map<String, Object>? underlyingValues]):
_underlyingValues = underlyingValues ?? <String, Object>{};
Expand Down