def test_release_is_unadopted_without_sessions(self): # This test should verify that releases that have no sessions (i.e. no result from snuba) # get marked as unadopted now = timezone.now() self.rpe.update(adopted=now) assert ReleaseProjectEnvironment.objects.filter( project_id=self.project1.id, release_id=self.release.id, environment_id=self.environment.id, adopted=now, unadopted=None, ).exists() test_data = [ { "org_id": [self.organization.id], "project_id": [self.project2.id, self.project1.id], }, ] process_projects_with_sessions(test_data[0]["org_id"][0], test_data[0]["project_id"]) assert ReleaseProjectEnvironment.objects.filter( project_id=self.project1.id, release_id=self.release.id, environment_id=self.environment.id, adopted=now, unadopted__gte=now, ).exists()
def test_simple_no_sessions(self): now = timezone.now() assert ReleaseProjectEnvironment.objects.filter( project_id=self.project1.id, release_id=self.release.id, environment_id=self.environment.id, adopted=None, ).exists() assert ReleaseProjectEnvironment.objects.filter( project_id=self.project2.id, release_id=self.release.id, environment_id=self.environment2.id, adopted=None, ).exists() assert not ReleaseProjectEnvironment.objects.filter( project_id=self.project1.id, release_id=self.release.id, environment_id=self.environment.id, adopted__gte=now, ).exists() assert not ReleaseProjectEnvironment.objects.filter( project_id=self.project2.id, release_id=self.release.id, environment_id=self.environment2.id, adopted__gte=now, ).exists() test_data = [ { "org_id": [self.organization.id], "project_id": [self.project2.id, self.project1.id], }, ] process_projects_with_sessions(test_data[0]["org_id"][0], test_data[0]["project_id"]) assert ReleaseProjectEnvironment.objects.filter( project_id=self.project1.id, release_id=self.release.id, environment_id=self.environment.id, adopted=None, ).exists() assert ReleaseProjectEnvironment.objects.filter( project_id=self.project2.id, release_id=self.release.id, environment_id=self.environment2.id, adopted=None, ).exists() assert not ReleaseProjectEnvironment.objects.filter( project_id=self.project1.id, release_id=self.release.id, environment_id=self.environment.id, adopted__gte=now, ).exists() assert not ReleaseProjectEnvironment.objects.filter( project_id=self.project2.id, release_id=self.release.id, environment_id=self.environment2.id, adopted__gte=now, ).exists()
def test_missing_rpe_is_created(self): self.bulk_store_sessions([ self.build_session(project_id=self.project1, release=self.release2, environment="somenvname") for _ in range(20) ]) self.bulk_store_sessions([ self.build_session(project_id=self.project1, release=self.release2, environment="") for _ in range(20) ]) now = timezone.now() assert not ReleaseProjectEnvironment.objects.filter( project_id=self.project1.id, release_id=self.release.id, environment__name="somenvname", ).exists() assert not ReleaseProjectEnvironment.objects.filter( project_id=self.project1.id, release_id=self.release2.id, environment__name="", ).exists() test_data = [ { "org_id": [self.organization.id], "project_id": [self.project2.id, self.project1.id], }, ] # This will make the appropriate models (Environment, ReleaseProject, ReleaseEnvironment and ReleaseProjectEnvironment) process_projects_with_sessions(test_data[0]["org_id"][0], test_data[0]["project_id"]) assert ReleaseProjectEnvironment.objects.filter( project_id=self.project1.id, release_id=self.release2.id, environment__name="somenvname", adopted__gte=now, ).exists() assert not ReleaseProjectEnvironment.objects.filter( project_id=self.project1.id, release_id=self.release2.id, environment__name="", ).exists()
def test_simple(self): self.bulk_store_sessions( [self.build_session(project_id=self.project1) for _ in range(11)]) self.bulk_store_sessions([ self.build_session(project_id=self.project2, environment=self.environment2.name) for _ in range(1) ]) assert self.project1.flags.has_sessions.is_set is False now = timezone.now() assert ReleaseProjectEnvironment.objects.filter( project_id=self.project1.id, release_id=self.release.id, environment_id=self.environment.id, adopted=None, ).exists() assert ReleaseProjectEnvironment.objects.filter( project_id=self.project2.id, release_id=self.release.id, environment_id=self.environment2.id, adopted=None, ).exists() assert not ReleaseProjectEnvironment.objects.filter( project_id=self.project1.id, release_id=self.release.id, environment_id=self.environment.id, adopted__gte=now, ).exists() assert not ReleaseProjectEnvironment.objects.filter( project_id=self.project2.id, release_id=self.release.id, environment_id=self.environment2.id, adopted__gte=now, ).exists() test_data = [ { "org_id": [self.organization.id], "project_id": [self.project2.id, self.project1.id], }, ] process_projects_with_sessions(test_data[0]["org_id"][0], test_data[0]["project_id"]) self.project1.refresh_from_db() assert self.project1.flags.has_sessions.is_set is True assert not ReleaseProjectEnvironment.objects.filter( project_id=self.project1.id, release_id=self.release.id, environment_id=self.environment.id, adopted=None, ).exists() assert ReleaseProjectEnvironment.objects.filter( project_id=self.project1.id, release_id=self.release.id, environment_id=self.environment.id, adopted__gte=now, ).exists() assert ReleaseProjectEnvironment.objects.filter( project_id=self.project2.id, release_id=self.release.id, environment_id=self.environment2.id, adopted__gte=now, ).exists()
def test_multi_proj_env_release_counter(self): self.bulk_store_sessions([ self.build_session(project_id=self.project1, ) for _ in range(11) ]) self.bulk_store_sessions([ self.build_session(project_id=self.project2, environment=self.environment2) for _ in range(1) ]) self.bulk_store_sessions([ self.build_session(project_id=self.project1, release=self.release2) for _ in range(1) ]) self.bulk_store_sessions([ self.build_session(project_id=self.project1, release=self.release3) for _ in range(1) ]) now = timezone.now() assert ReleaseProjectEnvironment.objects.filter( project_id=self.project1.id, release_id=self.release.id, environment_id=self.environment.id, adopted=None, ).exists() assert ReleaseProjectEnvironment.objects.filter( project_id=self.project2.id, release_id=self.release.id, environment_id=self.environment2.id, adopted=None, ).exists() assert not ReleaseProjectEnvironment.objects.filter( project_id=self.project1.id, release_id=self.release.id, environment_id=self.environment.id, adopted__gte=now, ).exists() assert not ReleaseProjectEnvironment.objects.filter( project_id=self.project2.id, release_id=self.release.id, environment_id=self.environment2.id, adopted__gte=now, ).exists() test_data = [ { "org_id": [self.organization.id], "project_id": [self.project2.id, self.project1.id], }, ] process_projects_with_sessions(test_data[0]["org_id"][0], test_data[0]["project_id"]) assert not ReleaseProjectEnvironment.objects.filter( project_id=self.project1.id, release_id=self.release.id, environment_id=self.environment.id, adopted=None, ).exists() assert ReleaseProjectEnvironment.objects.filter( project_id=self.project1.id, release_id=self.release.id, environment_id=self.environment.id, adopted__gte=now, ).exists() assert ReleaseProjectEnvironment.objects.filter( project_id=self.project2.id, release_id=self.release.id, environment_id=self.environment2.id, adopted__gte=now, ).exists()
def test_release_is_unadopted_with_sessions(self): # Releases that are returned with sessions but no longer meet the threshold get unadopted self.bulk_store_sessions( [self.build_session(project_id=self.project1) for _ in range(1)]) self.bulk_store_sessions([ self.build_session(project_id=self.project2, environment=self.environment2) for _ in range(11) ]) self.bulk_store_sessions([ self.build_session(project_id=self.project1, release=self.release2) for _ in range(20) ]) now = timezone.now() self.rpe.update(adopted=now) self.rpe1.update(adopted=now) assert ReleaseProjectEnvironment.objects.filter( project_id=self.project1.id, release_id=self.release.id, environment_id=self.environment.id, adopted=now, unadopted=None, ).exists() assert ReleaseProjectEnvironment.objects.filter( project_id=self.project1.id, release_id=self.release2.id, environment_id=self.environment.id, adopted=now, unadopted=None, ).exists() test_data = [ { "org_id": [self.organization.id], "project_id": [self.project2.id, self.project1.id], }, ] process_projects_with_sessions(test_data[0]["org_id"][0], test_data[0]["project_id"]) assert ReleaseProjectEnvironment.objects.filter( project_id=self.project1.id, release_id=self.release.id, environment_id=self.environment.id, adopted=now, unadopted__gte=now, ).exists() assert not ReleaseProjectEnvironment.objects.filter( project_id=self.project1.id, release_id=self.release2.id, environment_id=self.environment.id, adopted=now, unadopted__gte=now, ).exists() assert not ReleaseProjectEnvironment.objects.filter( project_id=self.project2.id, release_id=self.release.id, environment_id=self.environment2.id, adopted=now, unadopted__gte=now, ).exists() # Make sure re-adopting works self.bulk_store_sessions( [self.build_session(project_id=self.project1) for _ in range(50)]) time.sleep(1) process_projects_with_sessions(test_data[0]["org_id"][0], test_data[0]["project_id"]) assert ReleaseProjectEnvironment.objects.filter( project_id=self.project1.id, release_id=self.release.id, environment_id=self.environment.id, adopted=now, # doesn't get updated, unadopted just gets set to null unadopted=None, ).exists()
def test_release_is_unadopted_with_sessions(self): # Releases that are returned with sessions but no longer meet the threshold get unadopted self.bulk_store_sessions( [ self.session_dict( i, self.project1.id, self.release.version, self.environment.name, ) for i in range(1) ] ) self.bulk_store_sessions( [ self.session_dict(i, self.project2.id, self.release.version, self.environment2.name) for i in range(11) ] ) self.bulk_store_sessions( [ self.session_dict(i, self.project1.id, self.release2.version, self.environment.name) for i in range(20) ] ) now = timezone.now() self.rpe.update(adopted=now) self.rpe1.update(adopted=now) assert ReleaseProjectEnvironment.objects.filter( project_id=self.project1.id, release_id=self.release.id, environment_id=self.environment.id, adopted=now, unadopted=None, ).exists() assert ReleaseProjectEnvironment.objects.filter( project_id=self.project1.id, release_id=self.release2.id, environment_id=self.environment.id, adopted=now, unadopted=None, ).exists() test_data = [ { "org_id": [self.organization.id], "project_id": [self.project2.id, self.project1.id], }, ] process_projects_with_sessions(test_data[0]["org_id"][0], test_data[0]["project_id"]) assert ReleaseProjectEnvironment.objects.filter( project_id=self.project1.id, release_id=self.release.id, environment_id=self.environment.id, adopted=now, unadopted__gte=now, ).exists() assert not ReleaseProjectEnvironment.objects.filter( project_id=self.project1.id, release_id=self.release2.id, environment_id=self.environment.id, adopted=now, unadopted__gte=now, ).exists() assert not ReleaseProjectEnvironment.objects.filter( project_id=self.project2.id, release_id=self.release.id, environment_id=self.environment2.id, adopted=now, unadopted__gte=now, ).exists()
def test_simple(self): self.bulk_store_sessions( [ self.session_dict( i, self.project1.id, self.release.version, self.environment.name, ) for i in range(11) ] ) self.bulk_store_sessions( [ self.session_dict(i, self.project2.id, self.release.version, self.environment2.name) for i in range(1) ] ) now = timezone.now() assert ReleaseProjectEnvironment.objects.filter( project_id=self.project1.id, release_id=self.release.id, environment_id=self.environment.id, adopted=None, ).exists() assert ReleaseProjectEnvironment.objects.filter( project_id=self.project2.id, release_id=self.release.id, environment_id=self.environment2.id, adopted=None, ).exists() assert not ReleaseProjectEnvironment.objects.filter( project_id=self.project1.id, release_id=self.release.id, environment_id=self.environment.id, adopted__gte=now, ).exists() assert not ReleaseProjectEnvironment.objects.filter( project_id=self.project2.id, release_id=self.release.id, environment_id=self.environment2.id, adopted__gte=now, ).exists() test_data = [ { "org_id": [self.organization.id], "project_id": [self.project2.id, self.project1.id], }, ] process_projects_with_sessions(test_data[0]["org_id"][0], test_data[0]["project_id"]) assert not ReleaseProjectEnvironment.objects.filter( project_id=self.project1.id, release_id=self.release.id, environment_id=self.environment.id, adopted=None, ).exists() assert ReleaseProjectEnvironment.objects.filter( project_id=self.project1.id, release_id=self.release.id, environment_id=self.environment.id, adopted__gte=now, ).exists() assert ReleaseProjectEnvironment.objects.filter( project_id=self.project2.id, release_id=self.release.id, environment_id=self.environment2.id, adopted__gte=now, ).exists()