From 1bd840ac8b42ac44931b7db066e3c3e957be7bb4 Mon Sep 17 00:00:00 2001 From: Toshiya Kobayashi Date: Thu, 27 Jun 2024 10:55:04 +0900 Subject: [PATCH] [incubator-kie-drools-5847] Flaky KieContainerTest.testIncrementalCompilationSynchronization timeout --- .../mvel/integrationtests/KieContainerTest.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/KieContainerTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/KieContainerTest.java index 0bebcd07b8e..7c85701728b 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/KieContainerTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/KieContainerTest.java @@ -27,6 +27,8 @@ import java.util.List; import org.apache.commons.io.IOUtils; +import org.drools.base.definitions.InternalKnowledgePackage; +import org.drools.base.definitions.rule.impl.RuleImpl; import org.drools.compiler.compiler.io.Folder; import org.drools.compiler.compiler.io.memory.MemoryFileSystem; import org.drools.compiler.kie.builder.impl.MemoryKieModule; @@ -38,6 +40,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; +import org.kie.api.KieBase; import org.kie.api.KieServices; import org.kie.api.builder.KieModule; import org.kie.api.builder.Message.Level; @@ -267,6 +270,13 @@ public void testIncrementalCompilationSynchronization() { Thread t = new Thread(() -> { for (int i = 1; i < 10; i++) { + while (!previousRuleExists(kieContainer, i)) { // if rule1 exists, we can change it to rule2 + try { + Thread.sleep(1); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } ReleaseId releaseId1 = kieServices.newReleaseId("org.kie.test", "sync-scanner-test", "1.0." + i); KieUtil.getKieModuleFromDrls(releaseId1, kieBaseTestConfiguration, createDRL("rule" + i)); kieContainer.updateToVersion(releaseId1); @@ -292,6 +302,13 @@ public void testIncrementalCompilationSynchronization() { } } + private static boolean previousRuleExists(KieContainer kieContainer, int i) { + KieBase kieBase = kieContainer.getKieBase(); + InternalKnowledgePackage internalKnowledgePackage = (InternalKnowledgePackage)kieBase.getKiePackage("org.kie.test"); + RuleImpl rule = internalKnowledgePackage.getRule("rule" + (i - 1)); + return rule != null; + } + @Test public void testMemoryFileSystemFolderUniqueness() { KieServices kieServices = KieServices.Factory.get();