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

Fix JSON logger reporting duplicate values despite configuration #28

Merged
merged 3 commits into from
Jul 16, 2024

Conversation

simon-ess
Copy link
Contributor

@simon-ess simon-ess commented May 31, 2024

This is (roughly) a cherry-pick of ce7bd90.

Fixes #30

Copy link
Member

@anjohnson anjohnson left a comment

Choose a reason for hiding this comment

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

I've been trying to merge this PR, but it breaks the tests.

On building the current GitHub origin/master branch at ebe7120, the program caPutJsonLogTest runs all its 499 tests successfully.

After hand-merging this PR's origin/cherry-pick branch locally into origin/master, caPutJsonLogTest hangs after printing 352 of the expected 499 results.

Checking out the tip of the cherry-pick branch at e183395 caPutJsonLogTest expects to run 375 tests, but it hangs after printing 331 results.

It seems that some of the test code is incompatible with duplicate values not being logged. I applied this change to the cherry-pick branch:

diff --git a/test/caPutJsonLogTest.cpp b/test/caPutJsonLogTest.cpp
index b6411d2..e135a7a 100644
--- a/test/caPutJsonLogTest.cpp
+++ b/test/caPutJsonLogTest.cpp
@@ -881,7 +881,7 @@ MAIN(caPutJsonLogTests)
     startIoc();
     CaPutJsonLogTask *logger =  CaPutJsonLogTask::getInstance();
     if (logger == NULL) testAbort("Failed to initialize logger.");
-    logger->initialize(logServerAddress.c_str(), caPutJsonLogOnChange);
+    logger->initialize(logServerAddress.c_str(), caPutJsonLogAll);
     testDiag("Test IOC ready");
     testIocReady.trigger();
 

The result runs to completion with all 375 tests passing.

It might be a good idea to try applying the change from this branch to earlier commits to find out if the problem appears in Matic's original or was added more recently.

It would also be good to add tests for the different settings; it's possible to switch modes at runtime so we don't have to fix all the tests, just ensure the setting in use is appropriate for each set of tests.

@simon-ess
Copy link
Contributor Author

@anjohnson - Good catch. There definitely seems to be an issue here in comparing arrays of strings; the comparison only compares the first entry in the string array; for the given test, since the first string is unchanged the "on change" check fails, even though the array has changed. As near as I can tell, despite adding the a_string to the types enum, it is never used: https://github.com/epics-modules/caPutLog/blob/master/caPutLogApp/caPutLogTask.h#L47

Anyhow, there are further issues in here that need to be looked at.

I'm tempted to apply your change for the time being and then create an issue to fix array put comparisons; I don't have a good sense of how much of a rabbit hole that will be. I agree that adding tests for multiple modes is a good idea, but again, rabbit hole...

Matic Pogacnik and others added 3 commits July 15, 2024 16:11
This check would stop the logging, but a better solution would
be for the reconfiguration to shut down and/or restart the thread
as appropriate.
For the implementation of the JSON logger, the array comparison was left out.
As such, when checking if the value had changed, we would only compare the
first of the values from an array. Thus a change from
```
[1, 2, 3] -> [1, 3, 4, 5, 6, 7]
```
would be listed as not changing, which is not the correct behaviour.
@simon-ess
Copy link
Contributor Author

@anjohnson - I have fixed the array comparison, which fixes the tests without the need for the change you suggested above.

I think it is true that we should add more varied tests, but I think it might be better to create a followup issue for that.

@anjohnson
Copy link
Member

Yea, thanks!

@anjohnson anjohnson merged commit f137ee1 into master Jul 16, 2024
10 checks passed
@anjohnson anjohnson deleted the cherry-pick branch July 16, 2024 20:21
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.

Array comparison does not work correctly
2 participants