fix(usage): wait for initial connection attempt
This commit is contained in:
1 parent
a381ea94fb
commit
7f710c2bc8
4 files changed
+22
-2
No files matched your search
@@ -43,6 +43,14 @@ describe("mobile usage environment scope", () => {
|
||||
).toEqual({ isPending: true, isPartial: false });
|
||||
});
|
||||
|
||||
it("waits for the first connection attempt", () => {
|
||||
expect(
|
||||
getEnvironmentUsageLoadingState([
|
||||
{ phase: "connecting", isPending: true, summary: null, error: null },
|
||||
]),
|
||||
).toEqual({ isPending: true, isPartial: false });
|
||||
});
|
||||
|
||||
it("isolates a selected environment and falls back when it disappears", () => {
|
||||
const options = [environment("healthy", "connected"), environment("down", "offline")];
|
||||
|
||||
|
||||
@@ -69,13 +69,15 @@ const usageByWindowAtom = Atom.family((key: string) =>
|
||||
const { environmentId } = option;
|
||||
const connectionResult = get(environmentCatalog.stateAtom(environmentId));
|
||||
// Keep reading the environment-scoped atom while disconnected so a prior
|
||||
// successful value remains visible. Only a connected query can keep the UI loading.
|
||||
// successful value remains visible. Wait through the first connection attempt,
|
||||
// then treat retries as terminal coverage so a down machine cannot block the UI.
|
||||
const result = get(serverEnvironment.usageSummary({ environmentId, input }));
|
||||
const failed = option.phase === "connected" && result._tag === "Failure";
|
||||
environments.push({
|
||||
...option,
|
||||
isPending:
|
||||
(option.phase === "available" && connectionResult.waiting) ||
|
||||
option.phase === "connecting" ||
|
||||
(option.phase === "connected" && result.waiting),
|
||||
error: failed ? "This environment could not report usage." : null,
|
||||
summary: Option.getOrNull(AsyncResult.value(result)),
|
||||
|
||||
@@ -87,6 +87,14 @@ describe("usage environment scope", () => {
|
||||
).toEqual({ isPending: true, isPartial: false });
|
||||
});
|
||||
|
||||
it("keeps the first connection attempt pending", () => {
|
||||
expect(
|
||||
getEnvironmentUsageLoadingState([
|
||||
{ phase: "connecting", isPending: true, summary: null, error: null },
|
||||
]),
|
||||
).toEqual({ isPending: true, isPartial: false });
|
||||
});
|
||||
|
||||
it("keeps a selected offline environment terminal and isolated", () => {
|
||||
const scope = resolveEnvironmentUsageScope(
|
||||
[environment("healthy", "connected"), environment("down", "offline")],
|
||||
|
||||
@@ -67,13 +67,15 @@ const usageByWindowAtom = Atom.family((key: string) =>
|
||||
const { environmentId } = option;
|
||||
const connectionResult = get(environmentCatalog.stateAtom(environmentId));
|
||||
// Keep reading the environment-scoped atom while disconnected so a prior
|
||||
// successful value remains visible. Only a connected query can keep the UI loading.
|
||||
// successful value remains visible. Wait through the first connection attempt,
|
||||
// then treat retries as terminal coverage so a down machine cannot block the UI.
|
||||
const result = get(serverEnvironment.usageSummary({ environmentId, input }));
|
||||
const failed = option.phase === "connected" && result._tag === "Failure";
|
||||
environments.push({
|
||||
...option,
|
||||
isPending:
|
||||
(option.phase === "available" && connectionResult.waiting) ||
|
||||
option.phase === "connecting" ||
|
||||
(option.phase === "connected" && result.waiting),
|
||||
error: failed ? "This environment could not report usage." : null,
|
||||
summary: Option.getOrNull(AsyncResult.value(result)),
|
||||
|
||||
Reference in new issue
Block a user