def test_redis_pw_protection(): def simulate_one(): accepted = np.random.randint(2) return pyabc.Particle(0, {}, 0.1, [], [], accepted) sampler = RedisEvalParallelSamplerServerStarter( # noqa: S106 password="******") try: # needs to be always set sampler.set_analysis_id("ana_id") sample = sampler.sample_until_n_accepted(10, simulate_one, 0) assert 10 == len(sample.get_accepted_population()) finally: sampler.shutdown()
def test_redis_multiprocess(): def simulate_one(): accepted = np.random.randint(2) return pyabc.Particle(0, {}, 0.1, [], [], accepted) sampler = RedisEvalParallelSamplerServerStarter(batch_size=3, workers=1, processes_per_worker=2) try: # id needs to be set sampler.set_analysis_id("ana_id") sample = sampler.sample_until_n_accepted(10, simulate_one, 0) assert 10 == len(sample.get_accepted_population()) finally: sampler.shutdown()
def test_redis_continuous_analyses(): """Test correct behavior of the redis server with multiple analyses.""" sampler = RedisEvalParallelSamplerServerStarter() try: sampler.set_analysis_id("id1") # try "starting a new run while the old one has not finished yet" with pytest.raises(AssertionError) as e: sampler.set_analysis_id("id2") assert "busy with an analysis " in str(e.value) # after stopping it should work sampler.stop() sampler.set_analysis_id("id2") finally: sampler.shutdown()