Skip to content

Make more tests robust and independent #546

@glatterf42

Description

@glatterf42

Unfortunately, despite our recent improvements in #543, we still see some apparent flakiness. Its main source seems to be the setup-graphviz action on the windows runners, which sometimes fails like this:

C:\ProgramData\Chocolatey\bin\choco.exe install graphviz
Chocolatey v2.3.0
Installing the following packages:
graphviz
By installing, you accept licenses for the packages.
Downloading package from source 'https://community.chocolatey.org/api/v2/'
[NuGet] Error downloading 'Graphviz.12.1.1 : chocolatey-core.extension [1.3.5, )' from 'https://community.chocolatey.org/api/v2/package/Graphviz/12.1.1'.
[NuGet] Response status code does not indicate success: 503 (Service Unavailable: Back-end server is at capacity).
[NuGet] Error downloading 'Graphviz.12.1.1 : chocolatey-core.extension [1.3.5, )' from 'https://community.chocolatey.org/api/v2/package/Graphviz/12.1.1'.
[NuGet] Response status code does not indicate success: 503 (Service Unavailable: Back-end server is at capacity).
Graphviz not installed. An error occurred during installation:
 Error downloading 'Graphviz.12.1.1 : chocolatey-core.extension [1.3.5, )' from 'https://community.chocolatey.org/api/v2/package/Graphviz/12.1.1'.
Graphviz package files install failed with exit code 1. Performing other installation steps.
The install of Graphviz was NOT successful.
Graphviz not installed. An error occurred during installation:
 Error downloading 'Graphviz.12.1.1 : chocolatey-core.extension [1.3.5, )' from 'https://community.chocolatey.org/api/v2/package/Graphviz/12.1.1'.

Chocolatey installed 0/1 packages. 1 packages failed.
 See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).

Failures
 - Graphviz (exited 1) - Graphviz not installed. An error occurred during installation:
 Error downloading 'Graphviz.12.1.1 : chocolatey-core.extension [1.3.5, )' from 'https://community.chocolatey.org/api/v2/package/Graphviz/12.1.1'.

In addition, there was a new flaky test today:

test_connect_message::AssertionError
      ____________________________ test_connect_message _____________________________
[gw0] win32 -- Python 3.9.13 C:\hostedtoolcache\windows\Python\3.9.13\x64\python.exe

capfd = <_pytest.capture.CaptureFixture object at 0x000001C064A052B0>
caplog = <_pytest.logging.LogCaptureFixture object at 0x000001C065035A30>
request = <FixtureRequest for <Function test_connect_message>>

    def test_connect_message(capfd, caplog, request):
        msg = (
            f"connected to database 'jdbc:hsqldb:mem://{request.node.name}_0' "
            "(user: ixmp)..."
        )
    
        ixmp.Platform(
            backend="jdbc",
            driver="hsqldb",
            url=f"jdbc:hsqldb:mem://{request.node.name}_0",
            log_level="INFO",
        )
    
        # Java code via JPype does not log to the standard Python logger
        assert not any(msg in m for m in caplog.messages)
    
        # NB cannot inspect capfd here. Depending on the order in which the tests were run,
        #    a previous run may have left the Java log level higher than INFO, in which
        #    case the Java Platform object would not write to stderr before set_log_level()
        #    in the above call. Try again now that the level is INFO:
        msg = (
            f"connected to database 'jdbc:hsqldb:mem://{request.node.name}_1' "
            "(user: ixmp)..."
        )
        ixmp.Platform(
            backend="jdbc",
            driver="hsqldb",
            url=f"jdbc:hsqldb:mem://{request.node.name}_1",
        )
    
        # Instead, log messages are printed to stdout
        captured = capfd.readouterr()
>       assert msg in captured.out
E       assert "connected to database 'jdbc:hsqldb:mem://test_connect_message_1' (user: ixmp)..." in ''
E        +  where '' = CaptureResult(out='', err="2024-09-26 05:51:51,552  INFO at.ac.iiasa.ixmp.Platform:182 - closed the connection to database 'jdbc:hsqldb:mem://test_connect_message_0'\r\n2024-09-26 05:51:51,708  INFO at.ac.iiasa.ixmp.Platform:165 - Welcome to the IX modeling platform!\r\n2024-09-26 05:51:51,708  INFO at.ac.iiasa.ixmp.Platform:166 -  connected to database 'jdbc:hsqldb:mem://test_connect_message_1' (user: ixmp)...\r\n").out

ixmp\tests\backend\test_jdbc.py:277: AssertionError
------------------------------ Captured log call ------------------------------
INFO     ixmp.backend.jdbc:jdbc.py:288 launching ixmp.Platform connected to jdbc:hsqldb:mem://test_connect_message_1

Which almost seems like out and err got mixed up in the CaptureResult. If this originates from one test changing the logging level without changing it back again, we should figure out a way to change the level just for this one test, without affecting the whole environment.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ciContinuous integration

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions