Skip to content
Closed
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
47 changes: 45 additions & 2 deletions src/app/components/apps-view/apps-view.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { MatTooltipModule } from '@angular/material/tooltip';
import { By, HAMMER_LOADER } from '@angular/platform-browser';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { RouterTestingModule } from '@angular/router/testing';
import { AppInfo } from '@app/models/app-info.model';
import { AppInfo, StateLog } from '@app/models/app-info.model';
import { SchedulerService } from '@app/services/scheduler/scheduler.service';
import { MockNgxSpinnerService, MockSchedulerService } from '@app/testing/mocks';
import { NgxSpinnerService } from 'ngx-spinner';
Expand Down Expand Up @@ -108,4 +108,47 @@ describe('AppsViewComponent', () => {
copyButton.triggerEventHandler('click', null);
expect(copyButtonSpy).toHaveBeenCalled();
});
});

it('should set lastStateChangeTime to the latest time in stateLog', () => {
const stateLogs = [
new StateLog(100, 'SUBMITTED'),
new StateLog(200, 'RUNNING'),
new StateLog(300, 'FINISHED')
];
const appInfo = new AppInfo(
'app-test',
'Memory: 10.0 MB, CPU: 1, pods: 1',
'Memory: 0.0 bytes, CPU: 0, pods: n/a',
'',
123,
null,
stateLogs,
null,
'FINISHED',
[]
);

appInfo.setLastStateChangeTime();

expect(appInfo.lastStateChangeTime).toBe(300);
});

it('should set lastStateChangeTime to 0 if stateLog is empty', () => {
const appInfo = new AppInfo(
'app-empty',
'Memory: 10.0 MB, CPU: 1, pods: 1',
'Memory: 0.0 bytes, CPU: 0, pods: n/a',
'',
123,
null,
[],
null,
'SUBMITTED',
[]
);

appInfo.setLastStateChangeTime();

expect(appInfo.lastStateChangeTime).toBe(0);
});
});
9 changes: 7 additions & 2 deletions src/app/models/app-info.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,16 @@ export class AppInfo {
public maxUsedResource: string,
public submissionTime: number,
public finishedTime: null | number,
public stateLog: Array<StateLog>,
public stateLog: Array<StateLog> = [], // Default to empty array
public lastStateChangeTime: null | number,
public applicationState: string,
public allocations: AllocationInfo[] | null
) {}
) {
// Ensure stateLog is always an array
if (!Array.isArray(this.stateLog)) {
this.stateLog = [];
}
}

get formattedSubmissionTime() {
const millisecs = Math.round(this.submissionTime / (1000 * 1000));
Expand Down