Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[incubator-kie-drools-5847] Flaky KieContainerTest.testIncrementalCom… #6002

Conversation

tkobayas
Copy link
Contributor

Comment on lines +273 to +279
while (!previousRuleExists(kieContainer, i)) { // if rule1 exists, we can change it to rule2
try {
Thread.sleep(1);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
Copy link
Contributor Author

@tkobayas tkobayas Jun 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the analysis: #5848 (comment)

The kbase update modification will be done by its own thread immediately or by main thread polling kbaseModificationsQueue later.
https://github.com/apache/incubator-kie-drools/blob/main/drools-kiesession/src/main/java/org/drools/kiesession/rulebase/SessionsAwareKnowledgeBase.java#L287-L297

    public void enqueueModification(Runnable modification) {
        if ( tryLockAndDeactivate() ) {
            try {
                modification.run();
            } finally {
                unlockAndActivate();
            }
        } else {
            kbaseModificationsQueue.offer(modification);
        }
    }

So we cannot assume that the update modifications will be done in the expected order. In the failure case, remove rule1, add rule2 was executed before remove rule0, add rule1, so there was no chance to remove rule1.

I think it's not an engine bug, but we should fix the test case. With the PR fix, we make sure that we call updateToVersion only when the previous rule exists.

The test case can still test the multi-thread concurrency of fireAllRules and updateToVersion. Is it fine for the test purpose? @mariofusco


Btw, this PR while and Thread.sleep logic is a naive approach and can be re-written by ScheduledExecutorService, but I think this one is concise and easier to understand.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tkobayas Great work in analyzing this issue and yes I agree that the problem is in how the test is written and its wrong assumption on the strict execution order and not in the actual code.

@tkobayas
Copy link
Contributor Author

tkobayas commented Jun 27, 2024

@mariofusco @lucamolteni @pibizza , please review. Thanks!

@tkobayas tkobayas merged commit c599c11 into apache:main Jul 1, 2024
10 checks passed
rgdoliveira pushed a commit to rgdoliveira/drools that referenced this pull request Jul 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Flaky KieContainerTest.testIncrementalCompilationSynchronization timeout
3 participants