Skip to content

Intermitted error in test_datasaver_scalars  #4666

Closed

Description

    @settings(max_examples=5, deadline=None,
              suppress_health_check=(HealthCheck.function_scoped_fixture,))
    @given(breakpoint=hst.integers(min_value=1, max_value=19),
           write_period=hst.floats(min_value=0.1, max_value=1.5),
           set_values=hst.lists(elements=hst.floats(), min_size=20, max_size=20),
           get_values=hst.lists(elements=hst.floats(), min_size=20, max_size=20))
    @pytest.mark.usefixtures('set_default_station_to_none')
    def test_datasaver_scalars(experiment, DAC, DMM, set_values, get_values,
                               breakpoint, write_period):
        no_of_runs = len(experiment)
    
        station = qc.Station(DAC, DMM)
    
        meas = Measurement(station=station)
        meas.write_period = write_period
    
        assert meas.write_period == write_period
    
        meas.register_parameter(DAC.ch1)
        meas.register_parameter(DMM.v1, setpoints=(DAC.ch1,))
    
        with meas.run() as datasaver:
            for set_v, get_v in zip(set_values[:breakpoint],
                                    get_values[:breakpoint]):
                datasaver.add_result((DAC.ch1, set_v), (DMM.v1, get_v))
    
            assert datasaver._dataset.number_of_results == 0
            sleep(write_period * 1.1)
            datasaver.add_result((DAC.ch1, set_values[breakpoint]),
                                 (DMM.v1, get_values[breakpoint]))
>           assert datasaver.points_written == breakpoint + 1
E           assert 0 == (1 + 1)
E            +  where 0 = <qcodes.dataset.measurements.DataSaver object at 0x000002006588C8B0>.points_written

See details in the log below.

errorlog.txt

Activity

  1. Sushant0X0 commented on Nov 14, 2026

    @Sushant0X0

    Hi! I'd like to work on this, if nobody else has picked it up.

    From the CI log, this looks like a timing flake in the test, not a DataSaver bug:

    • The failing example was breakpoint=1, write_period=0.1, and it passed on replay (Hypothesis reported Flaky).
    • In the failing runs the only flush is the one from __exit__, so add_result never saw write_period as elapsed after sleep(write_period * 1.1). Both points were still written on exit.
    • My guess: the 10 ms margin is below the Windows timer tick (~15.6 ms), so the sleep came up slightly short. I have not reproduced this.

    Also, the retry loop from #5583 only sleeps. Since a flush is only triggered from add_result, I don't think it can change points_written.

    Proposed fix, either:

    1. Wait until perf_counter() - datasaver._last_save_time > write_period holds before the final add_result, or
    2. Monkeypatch perf_counter so the test controls the clock (no real sleeping).

    Which do you prefer, and is this still seen in CI on current Python versions?

  2. jenshnielsen commented on Nov 18, 2026

    @jenshnielsen
    CollaboratorAuthor

    You are welcome to work on this but please check that the issue still exists. Please note that #8758 fixes similar issues and perhaps this one. The preference is likely option 2 to avoid any flakiness.

  3. Sushant0X0 commented on Nov 18, 2026

    @Sushant0X0

    Hi Jens Hedegaard Nielsen (@jenshnielsen) , I tried to reproduce this on current main (Windows, Python 3.13.14). The test passed 30/30 runs, and replaying the failing case from the original log (breakpoint=1, write_period=0.1) directly 200 times gave 0 failures. The original report was on Python 3.10, so I think the more precise sleep on Windows in newer Pythons may have fixed it.

  4. jenshnielsen commented on Nov 18, 2026

    @jenshnielsen
    CollaboratorAuthor

    Thansk for testing. I have not seen this in ci either for at least some time so lets close it

  5. Sushant0X0 commented on Nov 18, 2026

    @Sushant0X0

    Happy to help Jens Hedegaard Nielsen (@jenshnielsen) , please tell me if I could be of any more disposal to you regarding some open issue.

    Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions