Repository navigation
Expand file tree
/
Copy pathClientAdmissionControls.test.ts
More file actions
131 lines (119 loc) · 5.15 KB
/
Copy pathClientAdmissionControls.test.ts
File metadata and controls
131 lines (119 loc) · 5.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
import {
formatAdmissionFailure,
getConfiguredAdmission,
parseClientAdmissionControls
} from '../ClientAdmissionControls';
import { selectClientRoute } from '../routing';
describe(parseClientAdmissionControls.name, () => {
it.each([
{ argv: ['build'], remaining: ['build'], admission: undefined },
{ argv: ['build', '--no-wait'], remaining: ['build'], admission: { noWait: true } },
{ argv: ['--wait-timeout', '1.25', 'build'], remaining: ['build'], admission: { waitTimeoutMs: 1250 } },
{ argv: ['build', '--wait-timeout=0'], remaining: ['build'], admission: { waitTimeoutMs: 0 } },
{
argv: ['build', '--wait-timeout=2147483.647'],
remaining: ['build'],
admission: { waitTimeoutMs: 2147483647 }
},
{
argv: ['script', '--', '--no-wait', '--wait-timeout', '2'],
remaining: ['script', '--', '--no-wait', '--wait-timeout', '2'],
admission: undefined
}
])('parses $argv', ({ argv, remaining, admission }) => {
expect(parseClientAdmissionControls(argv)).toEqual({ argv: remaining, admission });
});
it.each([
['build', '--wait-timeout'],
['build', '--wait-timeout='],
['build', '--wait-timeout=-1'],
['build', '--wait-timeout=Infinity'],
['build', '--wait-timeout=1e3'],
['build', '--wait-timeout=2147483.648'],
['build', '--wait-timeout=2147483.6471'],
['build', '--wait-timeout=1', '--wait-timeout=2'],
['build', '--no-wait', '--wait-timeout=0'],
['build', '--no-wait=false']
])('rejects invalid admission arguments %j', (...argv) => {
expect(() => parseClientAdmissionControls(argv)).toThrow();
});
it('removes daemon-only controls before native fallback while retaining script arguments', () => {
expect(
selectClientRoute({
argv: ['build', '--no-daemon', '--no-wait', '--', '--wait-timeout=2'],
enabled: true,
environment: {},
rushx: false
})
).toEqual({
argv: ['build', '--', '--wait-timeout=2'],
nativeArgv: ['build', '--', '--wait-timeout=2'],
commandName: 'build',
daemon: false,
admission: { noWait: true }
});
});
});
describe(getConfiguredAdmission.name, () => {
it('marks the built-in default so it does not bound waiting behind a compatible build', () => {
expect(getConfiguredAdmission({ queueTimeoutSeconds: 30, explicit: false })).toEqual({
waitTimeoutMs: 30000,
waitTimeoutIsDefault: true
});
});
it('does not mark an explicitly configured timeout as the default', () => {
expect(getConfiguredAdmission({ queueTimeoutSeconds: 1.5, explicit: true })).toEqual({ waitTimeoutMs: 1500 });
});
});
describe(formatAdmissionFailure.name, () => {
it('explains a wait timeout and offers only the per-invocation way to wait longer', () => {
const message: string = formatAdmissionFailure('wait-timeout', { waitTimeoutMs: 5000 });
expect(message).toContain(
'daemon admission failed (wait-timeout): timed out after its 5s wait timeout waiting for'
);
expect(message).toContain('pass --wait-timeout <seconds>');
// Exporting it would break later commands of Rush versions that reject unknown RUSH_ variables.
expect(message).not.toContain('RUSH_DAEMON_QUEUE_TIMEOUT_SECONDS');
});
it('explains a no-wait failure', () => {
expect(formatAdmissionFailure('no-wait', { noWait: true })).toContain('--no-wait was specified');
});
it("prints the daemon's reason for a wait timeout instead of the generic explanation", () => {
const reason: string =
"The rushx script was not admitted before the daemon could restart for another request's environment. " +
'Use --wait-timeout <seconds> to wait longer.';
expect(formatAdmissionFailure('wait-timeout', { waitTimeoutMs: 5000 }, reason)).toBe(
`rush-client: daemon admission failed (wait-timeout): ${reason}\n`
);
});
it("adds the way to wait longer when the daemon's reason does not name it", () => {
expect(
formatAdmissionFailure(
'wait-timeout',
{ waitTimeoutMs: 5000 },
'The request was not admitted within 5000ms.'
)
).toBe(
'rush-client: daemon admission failed (wait-timeout): The request was not admitted within 5000ms. ' +
'To wait longer, pass --wait-timeout <seconds>.\n'
);
});
it("prints the daemon's reason for a no-wait failure", () => {
const reason: string =
'Another request is waiting to restart the daemon for its environment; ' +
'the rushx script did not wait for the restart.';
expect(formatAdmissionFailure('no-wait', { noWait: true }, reason)).toBe(
`rush-client: daemon admission failed (no-wait): ${reason}\n`
);
});
it('keeps the generic explanation when the daemon sent no reason', () => {
expect(formatAdmissionFailure('wait-timeout', { waitTimeoutMs: 5000 }, '')).toBe(
formatAdmissionFailure('wait-timeout', { waitTimeoutMs: 5000 })
);
expect(formatAdmissionFailure('no-wait', { noWait: true }, '')).toBe(
formatAdmissionFailure('no-wait', { noWait: true })
);
});
});