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

build_daemon: drop pkg:uuid dev_dep #3722

Merged
merged 2 commits into from
Jun 28, 2024
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
1 change: 0 additions & 1 deletion build_daemon/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ dev_dependencies:
mockito: ^5.0.0
test: ^1.25.5
test_descriptor: ^2.0.0
uuid: ^3.0.0

topics:
- build-runner
32 changes: 16 additions & 16 deletions build_daemon/test/daemon_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ import 'package:build_daemon/src/fakes/fake_builder.dart';
import 'package:build_daemon/src/fakes/fake_change_provider.dart';
import 'package:test/test.dart';
import 'package:test_descriptor/test_descriptor.dart' as d;
import 'package:uuid/uuid.dart';

import 'uuid.dart';

final defaultIdleTimeoutSec = defaultIdleTimeout.inSeconds;
void main() {
var testDaemons = <Process>[];
var testWorkspaces = <String>[];
var uuid = const Uuid();
group('Daemon', () {
setUp(() {
testDaemons.clear();
Expand All @@ -41,7 +41,7 @@ void main() {
}
});
test('can be stopped', () async {
var workspace = uuid.v1();
var workspace = generateV4UUID();
testWorkspaces.add(workspace);
var daemon = Daemon(workspace);
await daemon.start(
Expand All @@ -53,20 +53,20 @@ void main() {
await daemon.stop();
});
test('can run if no other daemon is running', () async {
var workspace = uuid.v1();
var workspace = generateV4UUID();
var daemon = await _runDaemon(workspace);
testDaemons.add(daemon);
expect(await _statusOf(daemon), 'RUNNING');
});
test('shuts down if no client connects', () async {
var workspace = uuid.v1();
var workspace = generateV4UUID();
var daemon = await _runDaemon(workspace, timeout: 1);
testDaemons.add(daemon);
expect(await daemon.exitCode, isNotNull);
});
test('can not run if another daemon is running in the same workspace',
() async {
var workspace = uuid.v1();
var workspace = generateV4UUID();
testWorkspaces.add(workspace);
var daemonOne =
await _runDaemon(workspace, timeout: defaultIdleTimeoutSec * 2);
Expand All @@ -77,8 +77,8 @@ void main() {
}, timeout: const Timeout.factor(2));
test('can run if another daemon is running in a different workspace',
() async {
var workspace1 = uuid.v1();
var workspace2 = uuid.v1();
var workspace1 = generateV4UUID();
var workspace2 = generateV4UUID();
testWorkspaces.addAll([workspace1, workspace2]);
var daemonOne = await _runDaemon(workspace1);
expect(await _statusOf(daemonOne), 'RUNNING');
Expand All @@ -87,7 +87,7 @@ void main() {
expect(await _statusOf(daemonTwo), 'RUNNING');
}, timeout: const Timeout.factor(2));
test('can start two daemons at the same time', () async {
var workspace = uuid.v1();
var workspace = generateV4UUID();
testWorkspaces.add(workspace);
var daemonOne = await _runDaemon(workspace);
expect(await _statusOf(daemonOne), 'RUNNING');
Expand All @@ -96,20 +96,20 @@ void main() {
testDaemons.addAll([daemonOne, daemonTwo]);
}, timeout: const Timeout.factor(2));
test('logs the version when running', () async {
var workspace = uuid.v1();
var workspace = generateV4UUID();
testWorkspaces.add(workspace);
var daemon = await _runDaemon(workspace);
testDaemons.add(daemon);
expect(await _statusOf(daemon), 'RUNNING');
expect(await Daemon(workspace).runningVersion(), currentVersion);
});
test('does not set the current version if not running', () async {
var workspace = uuid.v1();
var workspace = generateV4UUID();
testWorkspaces.add(workspace);
expect(await Daemon(workspace).runningVersion(), null);
});
test('logs the options when running', () async {
var workspace = uuid.v1();
var workspace = generateV4UUID();
testWorkspaces.add(workspace);
var daemon = await _runDaemon(workspace);
testDaemons.add(daemon);
Expand All @@ -118,12 +118,12 @@ void main() {
(await Daemon(workspace).currentOptions()).contains('foo'), isTrue);
});
test('does not log the options if not running', () async {
var workspace = uuid.v1();
var workspace = generateV4UUID();
testWorkspaces.add(workspace);
expect((await Daemon(workspace).currentOptions()).isEmpty, isTrue);
});
test('cleans up after itself', () async {
var workspace = uuid.v1();
var workspace = generateV4UUID();
testWorkspaces.add(workspace);
var daemon = await _runDaemon(workspace);
// Wait for the daemon to be running before checking the workspace exits.
Expand All @@ -135,7 +135,7 @@ void main() {
expect(Directory(daemonWorkspace(workspace)).existsSync(), isFalse);
});
test('daemon stops after file changes stream has error', () async {
var workspace = uuid.v1();
var workspace = generateV4UUID();
testWorkspaces.add(workspace);
var daemon =
await _runDaemon(workspace, errorChangeProviderAfterNSeconds: 1);
Expand All @@ -144,7 +144,7 @@ void main() {
expect(Directory(daemonWorkspace(workspace)).existsSync(), isFalse);
});
test('daemon stops after file changes stream is closed', () async {
var workspace = uuid.v1();
var workspace = generateV4UUID();
testWorkspaces.add(workspace);
var daemon =
await _runDaemon(workspace, closeChangeProviderAfterNSeconds: 1);
Expand Down
36 changes: 36 additions & 0 deletions build_daemon/test/uuid.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// Copied from https://github.com/dart-lang/sdk/blob/9d28b1eb9f9cfb7331fef25238be5cba593e37ac/pkg/frontend_server/lib/src/uuid.dart

import 'dart:math' show Random;

/// A UUID generator.
///
/// The generated values are 128 bit numbers encoded in a specific string
/// format.
///
/// Generate a version 4 (random) uuid. This is a uuid scheme that only uses
/// random numbers as the source of the generated uuid.
// TODO: replace with a MUCH more simple, random string that matches
// the use case.
String generateV4UUID() {
var special = 8 + _random.nextInt(4);

return '${_bitsDigits(16, 4)}${_bitsDigits(16, 4)}-'
'${_bitsDigits(16, 4)}-'
'4${_bitsDigits(12, 3)}-'
'${_printDigits(special, 1)}${_bitsDigits(12, 3)}-'
'${_bitsDigits(16, 4)}${_bitsDigits(16, 4)}${_bitsDigits(16, 4)}';
}

final Random _random = Random();

String _bitsDigits(int bitCount, int digitCount) =>
_printDigits(_generateBits(bitCount), digitCount);

int _generateBits(int bitCount) => _random.nextInt(1 << bitCount);

String _printDigits(int value, int count) =>
value.toRadixString(16).padLeft(count, '0');
2 changes: 1 addition & 1 deletion build_runner/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ $ dart run test

[Bazel]: https://bazel.build/
[`package:build`]: https://pub.dev/packages/build
[analysis_options]: https://github.com/dart-lang/build/blob/master/analysis/analysis_options.yaml
[analysis_options]: https://github.com/dart-lang/build/blob/master/analysis_options.yaml

[builder]: https://pub.dev/documentation/build/latest/build/Builder-class.html
[run_fn]: https://pub.dev/documentation/build_runner/latest/build_runner/run.html
Expand Down
Loading