forked from kubeflow/pipelines
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pulls most functions out of Status and into StatusUtils. Fixes run du…
…ration bug (kubeflow#1262)
- Loading branch information
1 parent
32d3aee
commit 32946a4
Showing
14 changed files
with
245 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
/* | ||
* Copyright 2018 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { NodePhase, hasFinished, statusBgColors, statusToBgColor, checkIfTerminated } from './StatusUtils'; | ||
|
||
describe('StatusUtils', () => { | ||
|
||
describe('hasFinished', () => { | ||
[NodePhase.ERROR, NodePhase.FAILED, NodePhase.SUCCEEDED, NodePhase.SKIPPED, NodePhase.TERMINATED].forEach(status => { | ||
it(`returns \'true\' if status is: ${status}`, () => { | ||
expect(hasFinished(status)).toBe(true); | ||
}); | ||
}); | ||
|
||
[NodePhase.PENDING, NodePhase.RUNNING, NodePhase.UNKNOWN, NodePhase.TERMINATING].forEach(status => { | ||
it(`returns \'false\' if status is: ${status}`, () => { | ||
expect(hasFinished(status)).toBe(false); | ||
}); | ||
}); | ||
|
||
it('returns \'false\' if status is undefined', () => { | ||
expect(hasFinished(undefined)).toBe(false); | ||
}); | ||
|
||
it('returns \'false\' if status is invalid', () => { | ||
expect(hasFinished('bad phase' as any)).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('statusToBgColor', () => { | ||
it('handles an invalid phase', () => { | ||
const consoleSpy = jest.spyOn(console, 'log').mockImplementationOnce(() => null); | ||
expect(statusToBgColor('bad phase' as any)).toEqual(statusBgColors.notStarted); | ||
expect(consoleSpy).toHaveBeenLastCalledWith('Unknown node phase:', 'bad phase'); | ||
}); | ||
|
||
it('handles an \'Unknown\' phase', () => { | ||
const consoleSpy = jest.spyOn(console, 'log').mockImplementationOnce(() => null); | ||
expect(statusToBgColor(NodePhase.UNKNOWN)).toEqual(statusBgColors.notStarted); | ||
expect(consoleSpy).toHaveBeenLastCalledWith('Unknown node phase:', 'Unknown'); | ||
}); | ||
|
||
it('returns color \'not started\' if status is undefined', () => { | ||
const consoleSpy = jest.spyOn(console, 'log').mockImplementationOnce(() => null); | ||
expect(statusToBgColor(undefined)).toEqual(statusBgColors.notStarted); | ||
expect(consoleSpy).toHaveBeenLastCalledWith('Unknown node phase:', undefined); | ||
}); | ||
|
||
it('returns color \'not started\' if status is \'Pending\'', () => { | ||
expect(statusToBgColor(NodePhase.PENDING)).toEqual(statusBgColors.notStarted); | ||
}); | ||
|
||
[NodePhase.ERROR, NodePhase.FAILED].forEach(status => { | ||
it(`returns color \'error\' if status is: ${status}`, () => { | ||
expect(statusToBgColor(status)).toEqual(statusBgColors.error); | ||
}); | ||
}); | ||
|
||
[NodePhase.RUNNING, NodePhase.TERMINATING].forEach(status => { | ||
it(`returns color \'running\' if status is: ${status}`, () => { | ||
expect(statusToBgColor(status)).toEqual(statusBgColors.running); | ||
}); | ||
}); | ||
|
||
[NodePhase.SKIPPED, NodePhase.TERMINATED].forEach(status => { | ||
it(`returns color \'terminated or skipped\' if status is: ${status}`, () => { | ||
expect(statusToBgColor(status)).toEqual(statusBgColors.terminatedOrSkipped); | ||
}); | ||
}); | ||
|
||
it('returns color \'succeeded\' if status is \'Succeeded\'', () => { | ||
expect(statusToBgColor(NodePhase.SUCCEEDED)).toEqual(statusBgColors.succeeded); | ||
}); | ||
}); | ||
|
||
describe('checkIfTerminated', () => { | ||
it('returns status \'terminated\' if status is \'failed\' and error message is \'terminated\'', () => { | ||
expect(checkIfTerminated(NodePhase.FAILED, 'terminated')).toEqual(NodePhase.TERMINATED); | ||
}); | ||
|
||
[ | ||
NodePhase.SUCCEEDED, | ||
NodePhase.ERROR, | ||
NodePhase.SKIPPED, | ||
NodePhase.PENDING, | ||
NodePhase.RUNNING, | ||
NodePhase.TERMINATING, | ||
NodePhase.UNKNOWN | ||
].forEach(status => { | ||
it(`returns the original status, even if message is 'terminated', if status is: ${status}`, () => { | ||
expect(checkIfTerminated(status, 'terminated')).toEqual(status); | ||
}); | ||
}); | ||
|
||
it('returns \'failed\' if status is \'failed\' and no error message is provided', () => { | ||
expect(checkIfTerminated(NodePhase.FAILED)).toEqual(NodePhase.FAILED); | ||
}); | ||
|
||
it('returns \'failed\' if status is \'failed\' and empty error message is provided', () => { | ||
expect(checkIfTerminated(NodePhase.FAILED, '')).toEqual(NodePhase.FAILED); | ||
}); | ||
|
||
it('returns \'failed\' if status is \'failed\' and arbitrary error message is provided', () => { | ||
expect(checkIfTerminated(NodePhase.FAILED, 'some random error')).toEqual(NodePhase.FAILED); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* Copyright 2019 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { logger } from '../lib/Utils'; | ||
|
||
export const statusBgColors = { | ||
error: '#fce8e6', | ||
notStarted: '#f7f7f7', | ||
running: '#e8f0fe', | ||
succeeded: '#e6f4ea', | ||
terminatedOrSkipped: '#f1f3f4', | ||
warning: '#fef7f0', | ||
}; | ||
|
||
export enum NodePhase { | ||
ERROR = 'Error', | ||
FAILED = 'Failed', | ||
PENDING = 'Pending', | ||
RUNNING = 'Running', | ||
SKIPPED = 'Skipped', | ||
SUCCEEDED = 'Succeeded', | ||
TERMINATING = 'Terminating', | ||
TERMINATED = 'Terminated', | ||
UNKNOWN = 'Unknown', | ||
} | ||
|
||
export function hasFinished(status?: NodePhase): boolean { | ||
switch (status) { | ||
case NodePhase.SUCCEEDED: // Fall through | ||
case NodePhase.FAILED: // Fall through | ||
case NodePhase.ERROR: // Fall through | ||
case NodePhase.SKIPPED: // Fall through | ||
case NodePhase.TERMINATED: | ||
return true; | ||
case NodePhase.PENDING: // Fall through | ||
case NodePhase.RUNNING: // Fall through | ||
case NodePhase.TERMINATING: // Fall through | ||
case NodePhase.UNKNOWN: | ||
return false; | ||
default: | ||
return false; | ||
} | ||
} | ||
|
||
export function statusToBgColor(status?: NodePhase, nodeMessage?: string): string { | ||
status = checkIfTerminated(status, nodeMessage); | ||
switch (status) { | ||
case NodePhase.ERROR: | ||
// fall through | ||
case NodePhase.FAILED: | ||
return statusBgColors.error; | ||
case NodePhase.PENDING: | ||
return statusBgColors.notStarted; | ||
case NodePhase.TERMINATING: | ||
// fall through | ||
case NodePhase.RUNNING: | ||
return statusBgColors.running; | ||
case NodePhase.SUCCEEDED: | ||
return statusBgColors.succeeded; | ||
case NodePhase.SKIPPED: | ||
// fall through | ||
case NodePhase.TERMINATED: | ||
return statusBgColors.terminatedOrSkipped; | ||
case NodePhase.UNKNOWN: | ||
// fall through | ||
default: | ||
logger.verbose('Unknown node phase:', status); | ||
return statusBgColors.notStarted; | ||
} | ||
} | ||
|
||
export function checkIfTerminated(status?: NodePhase, nodeMessage?: string): NodePhase | undefined { | ||
// Argo considers terminated runs as having "Failed", so we have to examine the failure message to | ||
// determine why the run failed. | ||
if (status === NodePhase.FAILED && nodeMessage === 'terminated') { | ||
status = NodePhase.TERMINATED; | ||
} | ||
return status; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.