Skip to content

Commit

Permalink
Add some debug info to test
Browse files Browse the repository at this point in the history
  • Loading branch information
nikita-tkachenko-datadog committed Apr 8, 2024
1 parent 24042d5 commit 114903e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,13 @@ public static void publishMetrics(DatadogClient client) {
}

private static int getCurrentRunCount(Computer[] computers) {
DatadogUtilities.severe(logger, null, "[TEST-DEBUG] checking current run count");
Set<Run<?, ?>> runs = new HashSet<>();
for (Computer computer : computers) {
DatadogUtilities.severe(logger, null, "[TEST-DEBUG] checking computer " + computer + ", " + computer.getName());
List<Executor> executors = computer.getExecutors();
for (Executor executor : executors) {
DatadogUtilities.severe(logger, null, "[TEST-DEBUG] checking executor " + executor + ", " + executor.getName());
Run<?, ?> run = getCurrentRun(executor);
if (run != null) {
runs.add(run);
Expand All @@ -136,6 +139,7 @@ private static int getCurrentRunCount(Computer[] computers) {
private static Run<?, ?> getCurrentRun(Executor executor) {
Queue.Executable executable = executor.getCurrentExecutable();
while (executable != null) {
DatadogUtilities.severe(logger, null, "[TEST-DEBUG] checking executable " + executable + ": " + (executable instanceof Run) + "(" + executable.getParent() + ")") ;
if (executable instanceof Run) {
return (Run<?, ?>) executable;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import hudson.model.FreeStyleProject;
import hudson.model.Label;
import hudson.model.labels.LabelAtom;
import hudson.model.queue.QueueTaskFuture;
import hudson.slaves.DumbSlave;
import hudson.slaves.EnvironmentVariablesNodeProperty;
import hudson.triggers.SCMTrigger.SCMTriggerCause;
Expand All @@ -41,8 +42,10 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import jenkins.model.Jenkins;
Expand Down Expand Up @@ -79,6 +82,8 @@

public class DatadogGraphListenerTest extends DatadogTraceAbstractTest {

private static final Logger logger = Logger.getLogger(DatadogGraphListenerTest.class.getName());

private static final String SAMPLE_SERVICE_NAME = "sampleServiceName";

@ClassRule
Expand Down Expand Up @@ -1216,18 +1221,17 @@ public void testCurrentlyBuildingJobsMetric() throws Exception{
WorkflowJob job = jenkinsRule.jenkins.createProject(WorkflowJob.class, "testCurrentlyBuildingJobsMetricPipeline");
String definition = getPipelineDefinition("testPipelineComplexStages01.txt");
job.setDefinition(new CpsFlowDefinition(definition, true));
new Thread(() -> {
try {
job.scheduleBuild2(0).get();
} catch (Exception e) {
throw new RuntimeException(e);
}
}).start();

DatadogUtilities.severe(logger, null, "[TEST-DEBUG] scheduling build");
QueueTaskFuture<WorkflowRun> workflowRunQueueTaskFuture = job.scheduleBuild2(0);
DatadogUtilities.severe(logger, null, "[TEST-DEBUG] scheduled build: " + workflowRunQueueTaskFuture);

final DumbSlave worker03 = jenkinsRule.createOnlineSlave(Label.get("worker03"));
final DumbSlave worker02 = jenkinsRule.createOnlineSlave(Label.get("worker02"));

Thread.sleep(3000);
Future<WorkflowRun> startCondition = workflowRunQueueTaskFuture.getStartCondition();
WorkflowRun workflowRun = startCondition.get();
DatadogUtilities.severe(logger, null, "[TEST-DEBUG] build started: " + workflowRun);

// we know the pipeline is in progress at this point because it cannot complete until worker01 goes online
DatadogComputerPublisher.publishMetrics(clientStub);
Expand Down

0 comments on commit 114903e

Please sign in to comment.