Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
@TestOn('vm')
library;

import 'dart:async';

import 'package:devtools_app/devtools_app.dart';
import 'package:devtools_app_shared/shared.dart';
import 'package:devtools_app_shared/ui.dart';
Expand Down Expand Up @@ -47,7 +45,10 @@ void main() {
try {
group('inspector service tests', () {
tearDown(env.tearDownEnvironment);
tearDownAll(() => unawaited(env.tearDownEnvironment(force: true)));
tearDownAll(() async {
await env.tearDownEnvironment(force: true);
env.finalTeardown();
});
Comment thread
srawlins marked this conversation as resolved.

test('track widget creation on', () async {
await env.setupEnvironment();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,12 @@ class FlutterTestEnvironment {
_needsSetup = true;
}

/// Deletes the temporary directory created for the test suite.
void finalTeardown() {
// Delete the temporary directory created for the test suite.
if (_tempTestAppDirectory != null) {
final tempDirectory = Directory(_tempTestAppDirectory!);
if (_tempTestAppDirectory case final tempTestAppDirectory?) {
final tempDirectory = Directory(tempTestAppDirectory);
if (tempDirectory.existsSync()) {
Directory(_tempTestAppDirectory!).deleteSync(recursive: true);
tempDirectory.deleteSync(recursive: true);
}
Comment thread
srawlins marked this conversation as resolved.
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ void main() {
});

tearDown(() {
expect(
manager.expectedCommands.isEmpty,
true,
reason:
'stub does not receive expected command ${manager.expectedCommands}',
);
tmpDir.deleteSync(recursive: true);
try {
expect(
manager.expectedCommands.isEmpty,
true,
reason:
'stub does not receive expected command ${manager.expectedCommands}',
);
} finally {
tmpDir.deleteSync(recursive: true);
}
});

test('getBuildVariants calls flutter command correctly', () async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ class ExtensionTestManager {

Future<void> reset() async {
// Run with retry to ensure this deletes properly on Windows.
await deleteDirectoryWithRetry(testDirectory);
_testDirectory = null;
if (_testDirectory case final testDirectory?) {
await deleteDirectoryWithRetry(testDirectory);
_testDirectory = null;
}
_packagesRootUri = null;
_runtimeAppRoot = null;
}
Expand Down
14 changes: 6 additions & 8 deletions packages/devtools_shared/test/helpers/helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ Future<TestDtdConnectionInfo> startDtd() async {

class TestDartApp {
TestDartApp() {
directory = Directory(
'tmp/test_app_${DateTime.now().millisecondsSinceEpoch}',
);
directory = Directory.systemTemp.createTempSync('test_app_');
}
static final dartVMServiceRegExp = RegExp(
r'The Dart VM service is listening on (http://127.0.0.1:.*)',
Expand All @@ -78,7 +76,7 @@ class TestDartApp {
StreamSubscription<String>? _stderrSub;

Future<String> start() async {
await _initTestApp();
_initTestApp();
process = await Process.start(Platform.resolvedExecutable, [
'--observe=0',
'bin/main.dart',
Expand Down Expand Up @@ -122,10 +120,10 @@ class TestDartApp {
await deleteDirectoryWithRetry(directory);
}

Future<void> _initTestApp() async {
await deleteDirectoryWithRetry(directory);
directory.createSync(recursive: true);
Directory(path.join(directory.path, '.dart_tool')).createSync();
void _initTestApp() {
Directory(
path.join(directory.path, '.dart_tool'),
).createSync(recursive: true);

final mainFile = File(path.join(directory.path, 'bin', 'main.dart'))
..createSync(recursive: true);
Expand Down
6 changes: 3 additions & 3 deletions packages/devtools_shared/test/server/general_api_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ void main() {
expect(response.success, true);
expect(response.message, isNull);
expect(response.uri, isNotNull);
expect(response.uri!.toString(), endsWith(app!.directory.path));
expect(response.uri!.toFilePath(), endsWith(app!.directory.path));
});

test('succeeds for a disconnect event when cache is empty', () async {
Expand Down Expand Up @@ -223,7 +223,7 @@ void main() {
expect(response.success, true);
expect(response.message, isNull);
expect(response.uri, isNotNull);
expect(response.uri!.toString(), endsWith(app!.directory.path));
expect(response.uri!.toFilePath(), endsWith(app!.directory.path));

final disconnectResponse =
await server.VmServiceHandler.detectRootPackageForVmService(
Expand All @@ -236,7 +236,7 @@ void main() {
expect(disconnectResponse.message, isNull);
expect(disconnectResponse.uri, isNotNull);
expect(
disconnectResponse.uri!.toString(),
disconnectResponse.uri!.toFilePath(),
endsWith(app!.directory.path),
);
},
Expand Down
2 changes: 0 additions & 2 deletions packages/devtools_shared/test/utils/file_utils_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ void main() {
dtd?.process?.kill();
await dtd?.process?.exitCode;
dtd = null;
});

tearDownAll(() async {
// Run with retry to ensure this deletes properly on Windows.
await deleteDirectoryWithRetry(testDirectory);
});
Comment thread
srawlins marked this conversation as resolved.
Expand Down
94 changes: 51 additions & 43 deletions tool/lib/commands/rollback.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,51 +30,59 @@ class RollbackCommand extends Command {
final tempDir = (await io.Directory.systemTemp.createTemp(
'devtools-rollback',
)).absolute;
print('file://${tempDir.path}');
final tarball = io.File('${tempDir.path}/devtools.tar.gz');
final extractDir = await io.Directory(
'${tempDir.path}/extract/',
).absolute.create();
final client = io.HttpClient();
final version = argResults![_toVersionArg] as String;
print('downloading tarball to ${tarball.path}');
final tarballRequest = await client.getUrl(
Uri.http(
'storage.googleapis.com',
'pub-packages/packages/devtools-$version.tar.gz',
),
);
final tarballResponse = await tarballRequest.close();
await tarballResponse.pipe(tarball.openWrite());
print('Tarball written; unzipping.');
try {
print('file://${tempDir.path}');
final tarball = io.File('${tempDir.path}/devtools.tar.gz');
final extractDir = await io.Directory(
'${tempDir.path}/extract/',
).absolute.create();
final client = io.HttpClient();
final version = argResults![_toVersionArg] as String;
print('downloading tarball to ${tarball.path}');
final tarballRequest = await client.getUrl(
Uri.http(
'storage.googleapis.com',
'pub-packages/packages/devtools-$version.tar.gz',
),
);
final tarballResponse = await tarballRequest.close();
await tarballResponse.pipe(tarball.openWrite());
print('Tarball written; unzipping.');

await io.Process.run('tar', [
'-x',
'-z',
'-f',
tarball.path.split('/').last,
'-C',
extractDir.path,
], workingDirectory: tempDir.path);
print('file://${tempDir.path}');
await io.Process.run('tar', [
'-x',
'-z',
'-f',
tarball.path.split('/').last,
'-C',
extractDir.path,
], workingDirectory: tempDir.path);
print('file://${tempDir.path}');

final buildDir = io.Directory('${repo.repoPath}/packages/devtools/build/');
await buildDir.delete(recursive: true);
await io.Directory(
'${extractDir.path}build/',
).rename('${repo.repoPath}/packages/devtools/build/');
final buildDir = io.Directory(
'${repo.repoPath}/packages/devtools/build/',
);
await buildDir.delete(recursive: true);
await io.Directory(
'${extractDir.path}build/',
).rename('${repo.repoPath}/packages/devtools/build/');
Comment on lines +62 to +68

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

[CONCERN] If the build/ directory does not exist (for example, in a clean repository clone), buildDir.delete(recursive: true) will throw a FileSystemException and halt the rollback command.

Consider checking if the directory exists before attempting to delete it.

Suggested change
final buildDir = io.Directory(
'${repo.repoPath}/packages/devtools/build/',
);
await buildDir.delete(recursive: true);
await io.Directory(
'${extractDir.path}build/',
).rename('${repo.repoPath}/packages/devtools/build/');
final buildDir = io.Directory(
'${repo.repoPath}/packages/devtools/build/',
);
if (await buildDir.exists()) {
await buildDir.delete(recursive: true);
}
await io.Directory(
'${extractDir.path}build/',
).rename('${repo.repoPath}/packages/devtools/build/');
References
  1. Prefix every comment with a severity: [MUST-FIX], [CONCERN], [NIT] to categorize issues clearly. (link)


print(
'Build outputs from Devtools version $version checked out and moved '
'to ${buildDir.path}',
);
print(
'To complete the rollback, go to ${repo.repoPath}/packages/devtools, '
'rev pubspec.yaml, update the changelog, unhide build/ from the '
'packages/devtools/.gitignore file, then run pub publish.',
);
// TODO(djshuckerow): automatically rev pubspec.yaml and update the
// changelog so that the user can just run pub publish from
// packages/devtools.
print(
'Build outputs from Devtools version $version checked out and moved '
'to ${buildDir.path}',
);
print(
'To complete the rollback, go to ${repo.repoPath}/packages/devtools, '
'rev pubspec.yaml, update the changelog, unhide build/ from the '
'packages/devtools/.gitignore file, then run pub publish.',
);
// TODO(djshuckerow): automatically rev pubspec.yaml and update the
// changelog so that the user can just run pub publish from
// packages/devtools.
} finally {
if (await tempDir.exists()) {
await tempDir.delete(recursive: true);
}
}
}
}
4 changes: 2 additions & 2 deletions tool/test/license_utils_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void main() {
await _setupTestConfigFile();
});

tearDownAll(() async {
tearDown(() async {
await deleteDirectoryWithRetry(testDirectory);
});

Expand Down Expand Up @@ -171,7 +171,7 @@ text that should be removed from the file. */
await _setupTestDirectoryStructure();
});

tearDownAll(() async {
tearDown(() async {
await deleteDirectoryWithRetry(testDirectory);
});

Expand Down
Loading