Newer
Older
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
import {JobsService} from './jobs.service';
import {Job, JobExecution, JobSpec} from "../model/job";
import {HttpClientTestingModule, HttpTestingController} from "@angular/common/http/testing";
import {TestBed} from "@angular/core/testing";
import {ConfigurationService} from "../env/configuration.service";
export class FakeConfigurationService {
get config() {
return {
dryrun: "false",
rootDataDirectory: "/lustre/aoc/cluster/pipeline/vlass_test/spool",
url: "http://localhost:4200/VlassMngr",
weblogbaseurl: "http://webtest.aoc.nrao.edu/",
projectcode: "VLASS1.1",
wsurl: "ws://localhost:8081/VlassMngr/changes",
currentepoch: "1"
};
}
}
describe('JobsService', () => {
let httpMock: HttpTestingController;
let jobsService: JobsService;
let fakeConfigService: FakeConfigurationService;
let jobArray = [];
jobArray.push({
jobspec_id: 1,
jobspec_name: "JobSpec1",
jobspec_creation_date: 1563346880361,
jobspec_sdm_id: "Job1",
job_id: 2,
job_name: "Job2",
job_starttime: 1564785856832,
job_endtime: 1565212305634,
job_status: "QA_ACCEPTED",
job_arch_status: "ARCHIVED",
jobspec_creation_date_formatted: "07/17/2019, 12:01:20 AM",
job_starttime_formatted: "08/02/2019, 03:44:16 PM",
job_endtime_formatted: "08/07/2019, 02:11:45 PM",
jobspec_status: "QA_ACCEPTED"
} as Job);
jobArray.push({
jobspec_id: 3,
jobspec_name: "JobSpec3",
jobspec_creation_date: 1556849964313,
jobspec_sdm_id: "Job3",
job_id: 4,
job_name: "Job4",
job_starttime: 1565655567384,
job_endtime: null,
job_status: "PROCESSING",
job_arch_status: "UNARCHIVED",
jobspec_creation_date_formatted: "05/02/2019, 07:19:24 PM",
job_starttime_formatted: "08/12/2019, 05:19:27 PM",
job_endtime_formatted: "still going",
jobspec_status: "PROCESSING"
} as Job);
jobArray.push({
jobspec_id: 10,
jobspec_name: "JobSpec10",
jobspec_creation_date: 1557353188726,
jobspec_sdm_id: "Job10",
job_id: 11,
job_name: "Job11",
job_starttime: 1557353188764,
job_endtime: 1557421962191,
job_status: "ERROR",
job_arch_status: "UNARCHIVED",
jobspec_creation_date_formatted: "05/08/2019, 03:06:28 PM",
job_starttime_formatted: "05/08/2019, 03:06:28 PM",
job_endtime_formatted: "05/09/2019, 10:12:42 AM",
jobspec_status: "ERROR"
} as Job);
beforeEach(() => {
TestBed.configureTestingModule({
imports: [HttpClientTestingModule],
providers: [JobsService, {provide: ConfigurationService, useClass: FakeConfigurationService}]
});
jobsService = TestBed.get(JobsService);
httpMock = TestBed.get(HttpTestingController);
fakeConfigService = TestBed.get(ConfigurationService);
});
it('should return jobs', () => {
jobsService.getJobs('any', null, null, null).subscribe(response => {
expect(response).toEqual(jobArray, 'get jobs');
});
const req = httpMock.expectOne(fakeConfigService.config.url + jobsService.endPoint + 'optimized/queues/any');
expect(req.request.method).toBe("GET");
req.flush(jobArray);
httpMock.verify();
});
it('should return jobs filtered by id', () => {
jobsService.getJobs('any', '3', null, null).subscribe(response => {
expect(response[0]).toEqual(jobArray[1], 'get jobs with id');
});
const req = httpMock.expectOne(fakeConfigService.config.url + jobsService.endPoint + 'optimized/queues/any');
expect(req.request.method).toBe("GET");
req.flush(jobArray);
httpMock.verify();
});
it('should return jobs filtered by pattern', () => {
jobsService.getJobs('any', null, 'Spec1', null).subscribe(response => {
console.log('res', response);
expect(response.length).toBe(2, 'get jobs with pattern');
});
const req = httpMock.expectOne(fakeConfigService.config.url + jobsService.endPoint + 'optimized/queues/any');
expect(req.request.method).toBe("GET");
req.flush(jobArray);
httpMock.verify();
});
it('should return jobs filtered by status', () => {
jobsService.getJobs('any', null, null, 'QA_ACCEPTED').subscribe(response => {
expect(response[0]).toEqual(jobArray[0], 'get jobs with status');
});
const req = httpMock.expectOne(fakeConfigService.config.url + jobsService.endPoint + 'optimized/queues/any');
expect(req.request.method).toBe("GET");
req.flush(jobArray);
httpMock.verify();
});
it('should return a jobspec', () => {
const jobSpec = {
id: 1,
name: "JobSpec1",
creationDate: 1557353188726,
status: "ERROR",
targets: [],
inputs: null,
executions: [],
files: [],
queueName: "quicklook",
lastJob: null,
sbId: 3,
sdmId: "sdm3"
} as JobSpec;
jobsService.getJobSpec(1).subscribe(response => {
expect(response).toEqual(jobSpec, 'get job spec');
});
const req = httpMock.expectOne(fakeConfigService.config.url + jobsService.endPoint + 'specs/1');
expect(req.request.method).toBe("GET");
req.flush(jobSpec);
httpMock.verify();
});
it('should return a job', () => {
const job = {
"id": 2,
"name": "JobEx2",
"start": 1565655567384,
"end": null,
"status": "PROCESSING",
"jsonResults": null,
"analyst": null,
"notes": null,
"tasks": [],
"archivalJob": null,
"archiveStatus": "UNARCHIVED",
"queueName": "quicklook",
"sdmId": "sdm2",
"jobSpecId": 3,
"startDate": "08/12/2019, 05:19:27 PM",
"endDate": "still going"
} as JobExecution;
jobsService.getJob(2).subscribe(response => {
expect(response).toEqual(job, 'get job execution');
});
const req = httpMock.expectOne(fakeConfigService.config.url + jobsService.endPoint + 'jobs/2');
expect(req.request.method).toBe("GET");
req.flush(job);
httpMock.verify();
});
it('should create job', () => {
jobsService.createJob(1, 'calibration', 2).subscribe(response => {
expect(response).toEqual(200, 'create job');
});
const req = httpMock.expectOne(fakeConfigService.config.url + jobsService.endPoint + 'createJob?id=1&queue=calibration');
expect(req.request.method).toBe("POST");
req.flush(jobArray);
httpMock.verify();
});
it('should update job notes', () => {
jobsService.updateNotes(1, 'some notes').subscribe(response => {
expect(response).toEqual('some notes', 'update note');
});
const req = httpMock.expectOne(fakeConfigService.config.url + jobsService.endPoint + 'jobs/1/notes');
expect(req.request.method).toBe("PUT");
req.flush(jobArray);
httpMock.verify();
});
it('should update job status', () => {
jobsService.updateJobStatus(1, 'QA_PASSED', 'calibration').subscribe(response => {
expect(response).toEqual('QA_PASSED', 'update status');
});
const req = httpMock.expectOne(fakeConfigService.config.url + jobsService.endPoint + '/jobs/1/status?status=QA_PASSED&queue=calibration');
expect(req.request.method).toBe("PUT");
req.flush(jobArray);
const req2 = httpMock.expectOne(fakeConfigService.config.url + jobsService.endPoint + '/jobs/1/images?status=QA_PASSED&queue=calibration');
expect(req2.request.method).toBe("PUT");
req2.flush(jobArray);
httpMock.verify();
});
});