Regression test for race condition in batch logic. https://github.com/saltstack/salt/issues/56273
()
| 151 | |
| 152 | |
| 153 | def test_batch_issue_56273(): |
| 154 | """ |
| 155 | Regression test for race condition in batch logic. |
| 156 | https://github.com/saltstack/salt/issues/56273 |
| 157 | """ |
| 158 | |
| 159 | mock_pub = MockPub() |
| 160 | MockSubscriber.pubret = mock_pub |
| 161 | |
| 162 | def returns_for_job(jid): |
| 163 | return True |
| 164 | |
| 165 | opts = { |
| 166 | "conf_file": "", |
| 167 | "tgt": "minion*", |
| 168 | "fun": "state.sls", |
| 169 | "arg": ["foo"], |
| 170 | "timeout": 1, |
| 171 | "gather_job_timeout": 1, |
| 172 | "batch": 2, |
| 173 | "extension_modules": "", |
| 174 | "failhard": True, |
| 175 | } |
| 176 | with patch("salt.transport.tcp.PublishClient", MockSubscriber): |
| 177 | batch = salt.cli.batch.Batch(opts, quiet=True) |
| 178 | with patch.object(batch.local, "pub", Mock(side_effect=mock_pub)): |
| 179 | with patch.object( |
| 180 | batch.local, "returns_for_job", Mock(side_effect=returns_for_job) |
| 181 | ): |
| 182 | ret = list(batch.run()) |
| 183 | assert len(ret) == 4 |
| 184 | for val, _ in ret: |
| 185 | values = list(val.values()) |
| 186 | assert len(values) == 1 |
| 187 | assert values[0] is True |
| 188 | |
| 189 | |
| 190 | class MockPubSingleJid: |