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

fix(gui): Smoothening startup Part I #355

Merged
merged 5 commits into from
Oct 31, 2023
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
2 changes: 1 addition & 1 deletion end-to-end/organization_token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func TestOrganizationProvidedToken(t *testing.T) {
require.NoErrorf(t, err, "Setup: could not wake distro up: %v. %s", err, out)
}

const maxTimeout = 15 * time.Second
const maxTimeout = 30 * time.Second
EduardGomezEscandell marked this conversation as resolved.
Show resolved Hide resolved

if !tc.wantAttached {
time.Sleep(maxTimeout)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class AgentStartupMonitor {
/// The loop stops if a terminal condition is found or [timeout] expires.
Stream<AgentState> start({
Duration interval = const Duration(seconds: 1),
Duration timeout = const Duration(seconds: 30),
Duration timeout = const Duration(seconds: 5),
}) async* {
if (_addrFilePath == null) {
// Terminal state, cannot recover nor retry.
Expand Down Expand Up @@ -127,10 +127,16 @@ class AgentStartupMonitor {
// Terminal state, cannot recover nor retry.
return AgentState.unknownEnv;
case AgentAddrFileError.nonexistent:
// The directory must exist so we can watch for changes. This won't fail if the directory already exists.
final agentDir = await File(_addrFilePath!).parent.create();
final watch = agentDir
.watch(events: FileSystemEvent.create)
.firstWhere((event) => event.path.contains(_addrFilePath!));
if (!await agentLauncher()) {
// Terminal state, cannot recover nor retry.
return AgentState.cannotStart;
}
await watch;
return AgentState.starting;
// maybe a race condition allowed us to read the file before write completed? Retry.
// ignore: switch_case_completes_normally
Expand Down
26 changes: 26 additions & 0 deletions gui/packages/ubuntupro/test/startup/agent_monitor_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,32 @@ void main() {
verify(mockClient.ping()).called(1);
});

test('timeout if never addr', () async {
final mockClient = MockAgentApiClient();
// Fakes a successful ping.
when(mockClient.ping()).thenAnswer((_) async => true);
final monitor = AgentStartupMonitor(
/// A launch request will always succeed, but never writes the addr file.
agentLauncher: () async {
return true;
},
clientFactory: (port) => mockClient,
appName: kAppName,
addrFileName: kAddrFileName,
onClient: (_) {},
);

await expectLater(
monitor.start(interval: kInterval),
emitsInOrder([
AgentState.querying,
// instead of waiting the addr file to show up forever, we are caught by our internal timeout.
AgentState.unreachable,
]),
);
verifyNever(mockClient.ping());
});

test('await async onClient callback', () async {
final completeMe = Completer<void>();
final mockClient = MockAgentApiClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class MockAgentStartupMonitor extends _i1.Mock
@override
_i4.Stream<_i3.AgentState> start({
Duration? interval = const Duration(seconds: 1),
Duration? timeout = const Duration(seconds: 30),
Duration? timeout = const Duration(seconds: 5),
}) =>
(super.noSuchMethod(
Invocation.method(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class MockAgentStartupMonitor extends _i1.Mock
@override
_i5.Stream<_i4.AgentState> start({
Duration? interval = const Duration(seconds: 1),
Duration? timeout = const Duration(seconds: 30),
Duration? timeout = const Duration(seconds: 5),
}) =>
(super.noSuchMethod(
Invocation.method(
Expand Down
Loading