From a8d86907b6c8ef36964457ef5db4c54d1952c874 Mon Sep 17 00:00:00 2001 From: Vincent Latombe Date: Tue, 12 Nov 2024 15:44:58 +0100 Subject: [PATCH] Ensure NodeListener#onCreated is called once the Node initialization is complete Amends #9905 --- core/src/main/java/jenkins/model/Nodes.java | 4 ++-- test/src/test/java/jenkins/model/NodesTest.java | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/jenkins/model/Nodes.java b/core/src/main/java/jenkins/model/Nodes.java index a01c3fc342b5..ae78028c2d2f 100644 --- a/core/src/main/java/jenkins/model/Nodes.java +++ b/core/src/main/java/jenkins/model/Nodes.java @@ -118,6 +118,8 @@ public void setNodes(final @NonNull Collection nodes) throws IOE toRemove.putAll(Nodes.this.nodes); for (var node : nodes) { final var name = node.getNodeName(); + Nodes.this.nodes.put(name, node); + node.onLoad(Nodes.this, name); var oldNode = toRemove.get(name); if (oldNode != null) { NodeListener.fireOnUpdated(oldNode, node); @@ -125,8 +127,6 @@ public void setNodes(final @NonNull Collection nodes) throws IOE } else { NodeListener.fireOnCreated(node); } - Nodes.this.nodes.put(name, node); - node.onLoad(Nodes.this, name); } Nodes.this.nodes.keySet().removeAll(toRemove.keySet()); jenkins.updateComputerList(); diff --git a/test/src/test/java/jenkins/model/NodesTest.java b/test/src/test/java/jenkins/model/NodesTest.java index ef2bee08ef4a..5b222e313a5f 100644 --- a/test/src/test/java/jenkins/model/NodesTest.java +++ b/test/src/test/java/jenkins/model/NodesTest.java @@ -287,6 +287,7 @@ public static class CheckSetNodes extends NodeListener { @Override protected void onCreated(@NonNull Node node) { + node.getRootDir(); created.add(node.getNodeName()); }