Skip to content

Commit

Permalink
fix: handling remarks + revertiung docker-compose.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
carere committed Dec 16, 2024
1 parent 36219b7 commit f70b40c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 21 deletions.
5 changes: 2 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
services:
db:
container_name: postgres
#image: europe-west1-docker.pkg.dev/marble-infra/marble/postgresql-db:latest # custom image of postgres 15 with pg_cron extension added
image: postgres:15.2-alpine
image: europe-west1-docker.pkg.dev/marble-infra/marble/postgresql-db:latest # custom image of postgres 15 with pg_cron extension added
shm_size: 1g
restart: always
environment:
Expand All @@ -15,7 +14,7 @@ services:
volumes:
- postgres-db:/data/postgres
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
test: [ "CMD-SHELL", "pg_isready -U postgres" ]
interval: 2s
timeout: 1s
retries: 5
Expand Down
10 changes: 10 additions & 0 deletions mocks/scenario_testrun_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,13 @@ func (s *ScenarioTestrunRepository) ListTestRunsByScenarioID(ctx context.Context
}
return args.Get(0).([]models.ScenarioTestRun), args.Error(1)
}

func (s *ScenarioTestrunRepository) ListRunningTestRun(ctx context.Context,
exec repositories.Executor,
) ([]models.ScenarioTestRun, error) {
args := s.Called(ctx, exec)
if args.Get(0) == nil {
return nil, args.Error(1)
}
return args.Get(0).([]models.ScenarioTestRun), args.Error(1)
}
34 changes: 22 additions & 12 deletions repositories/scenario_testrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type ScenarioTestRunRepository interface {
testrunId string,
input models.ScenarioTestRunCreateDbInput,
) error
ListRunningTestRun(ctx context.Context, exec Executor) ([]models.ScenarioTestRun, error)
ListRunningTestRun(ctx context.Context, exec Executor, organizationId string) ([]models.ScenarioTestRun, error)
ListTestRunsByScenarioID(ctx context.Context, exec Executor, scenarioID string) ([]models.ScenarioTestRun, error)
GetTestRunByLiveVersionID(
ctx context.Context,
Expand Down Expand Up @@ -109,22 +109,32 @@ func (repo *MarbleDbRepository) GetTestRunByLiveVersionID(
}

func (repo *MarbleDbRepository) ListRunningTestRun(
ctx context.Context, exec Executor,
ctx context.Context, exec Executor, organizationId string,
) ([]models.ScenarioTestRun, error) {
if err := validateMarbleDbExecutor(exec); err != nil {
return nil, err
}
query := selectTestruns().
Where(squirrel.Eq{"status": models.Up}).
query := NewQueryBuilder().
Select(`
tr.id,
tr.scenario_iteration_id,
tr.live_scenario_iteration_id,
tr.created_at,
tr.expires_at,
tr.status`).
From(dbmodels.TABLE_SCENARIO_TESTRUN + " AS tr").
Join(dbmodels.TABLE_SCENARIO_ITERATIONS + " AS scit ON scit.id = tr.scenario_iteration_id").
Where(squirrel.And{
squirrel.Eq{"tr.status": models.Up},
squirrel.Eq{"scit.org_id": organizationId},
}).
OrderBy("created_at DESC")
testruns, err := SqlToListOfModels(ctx, exec, query, dbmodels.AdaptScenarioTestrun)
if err != nil {
return nil, err
}
if len(testruns) == 0 {
return nil, nil
}
return testruns, nil
return SqlToListOfModels(
ctx,
exec,
query,
dbmodels.AdaptScenarioTestrun,
)
}

func (repo *MarbleDbRepository) ListTestRunsByScenarioID(ctx context.Context,
Expand Down
9 changes: 3 additions & 6 deletions usecases/scenario_testrun_usecase.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (usecase *ScenarioTestRunUsecase) CreateScenarioTestRun(
}

// we should not have any existing testrun for this scenario
testRuns, err := usecase.repository.ListRunningTestRun(ctx, exec)
testRuns, err := usecase.repository.ListRunningTestRun(ctx, exec, organizationId)
if err != nil {
return models.ScenarioTestRun{}, err
}
Expand Down Expand Up @@ -164,10 +164,7 @@ func (usecase *ScenarioTestRunUsecase) CancelTestRunById(ctx context.Context,
if err := usecase.enforceSecurity.ReadTestRun(testRun.OrganizationId); err != nil {
return models.ScenarioTestRun{}, err
}
if testRun.Status == models.Down {
return testRun, nil
}
if testRun.Status == models.Up {
if testRun.Status != models.Down {
if err := usecase.repository.UpdateTestRunStatus(ctx,
exec, testRunId, models.Down); err != nil {
return models.ScenarioTestRun{}, err
Expand All @@ -181,5 +178,5 @@ func (usecase *ScenarioTestRunUsecase) CancelTestRunById(ctx context.Context,
}
return updatedTestRun, nil
}
return models.ScenarioTestRun{}, models.BadParameterError
return testRun, nil
}

0 comments on commit f70b40c

Please sign in to comment.