def test_experiments_recording(): Glean.set_experiment_active("experiment_test", "branch_a") Glean.set_experiment_active("experiment_api", "branch_b", {"test_key": "value"}) assert Glean.test_is_experiment_active("experiment_api") assert Glean.test_is_experiment_active("experiment_test") Glean.set_experiment_inactive("experiment_test") assert Glean.test_is_experiment_active("experiment_api") assert not Glean.test_is_experiment_active("experiment_test") stored_data = Glean.test_get_experiment_data("experiment_api") assert "branch_b" == stored_data.branch assert 1 == len(stored_data.extra) assert "value" == stored_data.extra["test_key"]
def __set__(self, experiment: Experiment, value: bool) -> None: """Called to set the 'active' status on an Experiment. This also updates the status in Glean. """ if value is True and self.values[experiment] is False: Glean.set_experiment_active( experiment_id=experiment.identifier, branch=experiment.branch, ) if value is False and self.values[experiment] is True: Glean.set_experiment_inactive(experiment.identifier) self.values[experiment] = value
def test_experiments_recording_before_glean_inits(): # This test relies on Glean not being initialized and task # queuing to be on. Glean.reset() Glean.set_experiment_active("experiment_set_preinit", "branch_a") Glean.set_experiment_active("experiment_preinit_disabled", "branch_a") Glean.set_experiment_inactive("experiment_preinit_disabled") # This will init Glean and flush the dispatcher's queue. Glean.initialize(application_id=GLEAN_APP_ID, application_version=glean_version) assert Glean.test_is_experiment_active("experiment_set_preinit") assert not Glean.test_is_experiment_active("experiment_preinit_disabled")