Skip to content

Commit

Permalink
♻️ [Test] Improved Job running checks while testing
Browse files Browse the repository at this point in the history
Signed-off-by: Alberto Codutti <[email protected]>
  • Loading branch information
Coduz committed Jan 20, 2025
1 parent bd9abbd commit 1ed1fe6
Showing 1 changed file with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2021, 2024 Eurotech and/or its affiliates and others
* Copyright (c) 2021, 2025 Eurotech and/or its affiliates and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -27,13 +27,17 @@
import org.eclipse.kapua.qa.common.StepData;
import org.eclipse.kapua.service.job.Job;
import org.junit.Assert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.inject.Inject;
import java.util.concurrent.TimeUnit;

@Singleton
public class JobEngineSteps extends JobServiceTestBase {

private static final Logger LOG = LoggerFactory.getLogger(JobEngineSteps.class);

private JobEngineService jobEngineService;
private JobEngineFactory jobEngineFactory;

Expand Down Expand Up @@ -83,8 +87,13 @@ public void waitJobInContextToStart(int waitSeconds) throws Exception {

long now = System.currentTimeMillis();
while ((System.currentTimeMillis() - now) < (waitSeconds * 1000L)) {
if (jobEngineService.isRunning(job.getScopeId(), job.getId())) {
return;
try {
if (jobEngineService.isRunning(job.getScopeId(), job.getId())) {
return;
}
}
catch (Exception e){
LOG.warn("Error while checking running status for Job {}. Ignoring... Error: {}", job.getName(), e.getMessage());
}

// Check frequently!
Expand Down Expand Up @@ -136,8 +145,13 @@ public void waitJobByNameUpTo(String jobName, int waitSeconds) throws Exception
private void waitJobUpTo(Job job, int waitSeconds) throws Exception {
long now = System.currentTimeMillis();
while ((System.currentTimeMillis() - now) < (waitSeconds * 1000L)) {
if (!jobEngineService.isRunning(job.getScopeId(), job.getId())) {
return;
try {
if (!jobEngineService.isRunning(job.getScopeId(), job.getId())) {
return;
}
}
catch (Exception e){
LOG.warn("Error while checking running status for Job {}. Ignoring... Error: {}", job.getName(), e.getMessage());
}

TimeUnit.MILLISECONDS.sleep(100);
Expand Down

0 comments on commit 1ed1fe6

Please sign in to comment.