Skip to content

Commit 49f7d9b

Browse files
author
Jérémy James Toussaint
committed
Update test for writting files to tmp
1 parent 46f9ae5 commit 49f7d9b

File tree

1 file changed

+33
-14
lines changed

1 file changed

+33
-14
lines changed

src/test/java/com/iexec/worker/compute/ComputeManagerServiceTests.java

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
import com.iexec.worker.docker.DockerService;
2828
import org.assertj.core.api.Assertions;
2929
import org.junit.Before;
30+
import org.junit.Rule;
3031
import org.junit.Test;
32+
import org.junit.rules.TemporaryFolder;
3133
import org.mockito.InjectMocks;
3234
import org.mockito.Mock;
3335
import org.mockito.MockitoAnnotations;
@@ -67,6 +69,9 @@ public class ComputeManagerServiceTests {
6769
private final ComputeResponsesHolder computeResponsesHolder =
6870
ComputeResponsesHolder.builder().chainTaskId(CHAIN_TASK_ID).build();
6971

72+
@Rule
73+
public TemporaryFolder jUnitTemporaryFolder = new TemporaryFolder();
74+
7075
@InjectMocks
7176
private ComputeManagerService computeManagerService;
7277
@Mock
@@ -83,7 +88,7 @@ public class ComputeManagerServiceTests {
8388
private IexecHubService iexecHubService;
8489

8590
@Before
86-
public void beforeEach() throws IOException {
91+
public void beforeEach() {
8792
MockitoAnnotations.initMocks(this);
8893

8994
}
@@ -137,7 +142,8 @@ public void shouldRunStandardPreCompute() {
137142
when(preComputeStepService.runStandardPreCompute(taskDescription,
138143
workerpoolAuthorization)).thenReturn(true);
139144

140-
computeManagerService.runPreCompute(computeResponsesHolder, taskDescription,
145+
computeManagerService.runPreCompute(computeResponsesHolder,
146+
taskDescription,
141147
workerpoolAuthorization);
142148
Assertions.assertThat(computeResponsesHolder.isPreComputed()).isTrue();
143149
verify(preComputeStepService, times(1))
@@ -151,7 +157,8 @@ public void shouldRunStandardPreComputeWithFailureResponse() {
151157
when(preComputeStepService.runStandardPreCompute(taskDescription,
152158
workerpoolAuthorization)).thenReturn(false);
153159

154-
computeManagerService.runPreCompute(computeResponsesHolder, taskDescription,
160+
computeManagerService.runPreCompute(computeResponsesHolder,
161+
taskDescription,
155162
workerpoolAuthorization);
156163
Assertions.assertThat(computeResponsesHolder.isPreComputed()).isFalse();
157164
}
@@ -162,7 +169,8 @@ public void shouldRunTeePreCompute() {
162169
when(preComputeStepService.runTeePreCompute(taskDescription,
163170
workerpoolAuthorization)).thenReturn(SECURE_SESSION_ID);
164171

165-
computeManagerService.runPreCompute(computeResponsesHolder, taskDescription,
172+
computeManagerService.runPreCompute(computeResponsesHolder,
173+
taskDescription,
166174
workerpoolAuthorization);
167175
Assertions.assertThat(computeResponsesHolder.isPreComputed()).isTrue();
168176
Assertions.assertThat(computeResponsesHolder.getSecureSessionId()).isEqualTo(SECURE_SESSION_ID);
@@ -177,7 +185,8 @@ public void shouldRunTeePreComputeWithFailureResponse() {
177185
when(preComputeStepService.runTeePreCompute(taskDescription,
178186
workerpoolAuthorization)).thenReturn("");
179187

180-
computeManagerService.runPreCompute(computeResponsesHolder, taskDescription,
188+
computeManagerService.runPreCompute(computeResponsesHolder,
189+
taskDescription,
181190
workerpoolAuthorization);
182191
Assertions.assertThat(computeResponsesHolder.isPreComputed()).isFalse();
183192
Assertions.assertThat(computeResponsesHolder.getSecureSessionId()).isEmpty();
@@ -193,7 +202,8 @@ public void shouldRunStandardCompute() {
193202
when(computeStepService.runCompute(taskDescription,
194203
"")).thenReturn(expectedDockerRunResponse);
195204

196-
computeManagerService.runCompute(computeResponsesHolder, taskDescription);
205+
computeManagerService.runCompute(computeResponsesHolder,
206+
taskDescription);
197207
Assertions.assertThat(computeResponsesHolder.isComputed()).isTrue();
198208
Assertions.assertThat(computeResponsesHolder.getComputeDockerRunResponse())
199209
.isEqualTo(expectedDockerRunResponse);
@@ -210,14 +220,15 @@ public void shouldRunStandardComputeWithFailureResponse() {
210220
when(computeStepService.runCompute(taskDescription,
211221
"")).thenReturn(expectedDockerRunResponse);
212222

213-
computeManagerService.runCompute(computeResponsesHolder, taskDescription);
223+
computeManagerService.runCompute(computeResponsesHolder,
224+
taskDescription);
214225
Assertions.assertThat(computeResponsesHolder.isComputed()).isFalse();
215226
Assertions.assertThat(computeResponsesHolder.getComputeDockerRunResponse())
216227
.isEqualTo(expectedDockerRunResponse);
217228
}
218229

219230
@Test
220-
public void shouldRunTeeCompute() {
231+
public void shouldRunTeeCompute() throws IOException {
221232
taskDescription.setTeeTask(true);
222233
computeResponsesHolder.setSecureSessionId(SECURE_SESSION_ID);
223234
DockerRunResponse expectedDockerRunResponse =
@@ -229,8 +240,11 @@ public void shouldRunTeeCompute() {
229240
.build();
230241
when(computeStepService.runCompute(taskDescription,
231242
SECURE_SESSION_ID)).thenReturn(expectedDockerRunResponse);
243+
when(workerConfigurationService.getTaskIexecOutDir(CHAIN_TASK_ID))
244+
.thenReturn(jUnitTemporaryFolder.newFolder().getAbsolutePath());
232245

233-
computeManagerService.runCompute(computeResponsesHolder, taskDescription);
246+
computeManagerService.runCompute(computeResponsesHolder,
247+
taskDescription);
234248
Assertions.assertThat(computeResponsesHolder.isComputed()).isTrue();
235249
Assertions.assertThat(computeResponsesHolder.getComputeDockerRunResponse())
236250
.isEqualTo(expectedDockerRunResponse);
@@ -250,7 +264,8 @@ public void shouldRunTeeComputeWithFailure() {
250264
when(computeStepService.runCompute(taskDescription,
251265
SECURE_SESSION_ID)).thenReturn(expectedDockerRunResponse);
252266

253-
computeManagerService.runCompute(computeResponsesHolder, taskDescription);
267+
computeManagerService.runCompute(computeResponsesHolder,
268+
taskDescription);
254269
Assertions.assertThat(computeResponsesHolder.isComputed()).isFalse();
255270
Assertions.assertThat(computeResponsesHolder.getComputeDockerRunResponse())
256271
.isEqualTo(expectedDockerRunResponse);
@@ -264,7 +279,8 @@ public void shouldRunStandardPostCompute() {
264279
when(postComputeStepService.runStandardPostCompute(taskDescription))
265280
.thenReturn(true);
266281

267-
computeManagerService.runPostCompute(computeResponsesHolder, taskDescription);
282+
computeManagerService.runPostCompute(computeResponsesHolder,
283+
taskDescription);
268284
Assertions.assertThat(computeResponsesHolder.isPostComputed()).isTrue();
269285
verify(postComputeStepService, times(1))
270286
.runStandardPostCompute(taskDescription);
@@ -276,7 +292,8 @@ public void shouldRunStandardPostComputeWithFailureResponse() {
276292
when(postComputeStepService.runStandardPostCompute(taskDescription))
277293
.thenReturn(false);
278294

279-
computeManagerService.runPostCompute(computeResponsesHolder, taskDescription);
295+
computeManagerService.runPostCompute(computeResponsesHolder,
296+
taskDescription);
280297
Assertions.assertThat(computeResponsesHolder.isPostComputed()).isFalse();
281298
}
282299

@@ -295,7 +312,8 @@ public void shouldRunTeePostCompute() {
295312
SECURE_SESSION_ID))
296313
.thenReturn(expectedDockerRunResponse);
297314

298-
computeManagerService.runPostCompute(computeResponsesHolder, taskDescription);
315+
computeManagerService.runPostCompute(computeResponsesHolder,
316+
taskDescription);
299317
Assertions.assertThat(computeResponsesHolder.isPostComputed()).isTrue();
300318
verify(postComputeStepService, times(1))
301319
.runTeePostCompute(taskDescription, SECURE_SESSION_ID);
@@ -315,7 +333,8 @@ public void shouldRunTeePostComputeWithFailureResponse() {
315333
when(postComputeStepService.runTeePostCompute(taskDescription, ""))
316334
.thenReturn(expectedDockerRunResponse);
317335

318-
computeManagerService.runPostCompute(computeResponsesHolder, taskDescription);
336+
computeManagerService.runPostCompute(computeResponsesHolder,
337+
taskDescription);
319338
Assertions.assertThat(computeResponsesHolder.isPostComputed()).isFalse();
320339
}
321340

0 commit comments

Comments
 (0)