JSON unit test failing occasionally


#1

I was checking the unit tests in the Juce Demo and noticed that the JSON unit tests occasionally fail when parsing the random vars (line 636 of juce_JSON.cpp). It can take a number of runs to see it come up, but I've confirmed it with the latest tip.

To make it easier to replicate I did a bit of debugging and came up with following repro (just keep the rest of JSONTests as is):


    void runTest () override
    {
        beginTest ("JSON");
        var v;
        Random r (0xc7764c);
        bool oneLine; 
        for (int i = 1000; --i >= 563;)
        {
            if (i > 0)
                v = createRandomVar (r, 0);
            oneLine = r.nextBool ();
        }
            
        String asString (JSON::toString (v, oneLine));
        var parsed = JSON::parse ("[" + asString + "]")[0];
        String parsedString (JSON::toString (parsed, oneLine));
        expect (asString.isNotEmpty () && parsedString == asString);
    }

#2

Yeah, I've seen this too, but I think it's just an edge-case where very large double values are being converted to strings and back to doubles, and lose a tiny amount of precision in the process. Don't think it would impact any real-world code.


#3

Fair enough!


#4

I'm at GIT TAG 4.0.1 

I noticed JSON test fail , even though the test runner showed all tests passed at the very end result, there was one that didn't I happened to catch it as it flew by the screen

Starting test: JSON / JSON...
!!! Test 97 failed
FAILED!!  1 test failed, out of a total of 109
 

The test runner showed evertyhing was fine but one test in the mix failed, is there some way to ignore certain test failures or could there be a problem with test runner?

 

 

 

 

 


#5

Ah, we get occasional failures in that one because of string<->int conversion rounding errors, it's not a real problem but we should probably make the test a little more forgiving..


#6

i know i’m a bit pedantic, but this should be fixed. we cannot rely on any CI setup if we have random failures for juce unit tests.

ps. i’m also getting random failures in TimeTests:

    expect (Time::fromISO8601 (t.toISO8601 (true)) == t);

#7

Good call, I’ll check that again.

I’ve actually never seen a problem with the Time tests - perhaps there’s something different about the locale you’re using - what time zone are you in?


#8

CEST at the moment