forked from G-Research/fasttrackml
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Aim integration tests for runs endpoints (G-Research#187)
* WIP for testing the GetRunInfo api * Use response struct for test unmarshalling * WIP for verifying GetRunInfo * Add test for runs/active endpoint * Fix merge from main * Added UpdateRun test; moved some /api/aim/api/ to /api/aim * Remove extraneous cleanup, and add a couple * get_run_metrics_test and gofumpt * added convenience to create metrics sequence * GetRunMetrics test * Create singular fixtures.CreateExampleRun and use in tests * Verify run metric values returned by the endpoint * PR change requests * merge main fixes * Lint complaints * PR change requests * Update experiment tests * Simplified test with response expectation * Test fixes for PR * Test no-data GetActiveRuns better * formatting change
- Loading branch information
Showing
17 changed files
with
685 additions
and
25 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package request | ||
|
||
// UpdateRunRequest is a request struct for `PUT /runs/:id` endpoint. | ||
type UpdateRunRequest struct { | ||
RunID *string `json:"run_id"` | ||
RunUUID *string `json:"run_uuid"` | ||
Name *string `json:"run_name"` | ||
Description *string `json:"description"` | ||
Status *string `json:"status"` | ||
EndTime *int64 `json:"end_time"` | ||
Archived *bool `json:"archived"` | ||
} | ||
|
||
// GetRunMetrics is a request struct for `POST /runs/:id/metric/get-batch` | ||
type GetRunMetrics []GetRunMetric | ||
|
||
// GetRunMetric is one element of GetRunMetricsRequest | ||
type GetRunMetric struct { | ||
Context map[string]string `json:"context"` | ||
Name string `json:"name"` | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package response | ||
|
||
// GetRunInfo represents the response struct for GetRunInfo endpoint | ||
type GetRunInfo struct { | ||
Params GetRunInfoParams `json:"params"` | ||
Traces GetRunInfoTraces `json:"traces"` | ||
Props GetRunInfoProps `json:"props"` | ||
} | ||
|
||
// GetRunsActive represents the response struct for GetRunsActive endpoint | ||
type GetRunsActive map[string]GetRunInfo | ||
|
||
// GetRunInfoParams params | ||
type GetRunInfoParams struct { | ||
Tags map[string]string `json:"tags"` | ||
} | ||
|
||
// GetRunInfoTraces traces | ||
type GetRunInfoTraces struct { | ||
Tags map[string]string `json:"tags"` | ||
} | ||
|
||
// GetRunInfoProps run properties | ||
type GetRunInfoProps struct { | ||
ID string `json:"id"` | ||
Name string `json:"name"` | ||
Description string `json:"description"` | ||
Experiment GetRunInfoExperiment `json:"experiment"` | ||
Tags []string `json:"tags"` | ||
CreationTime int64 `json:"creation_time"` | ||
EndTime int64 `json:"end_time"` | ||
Archived bool `json:"archived"` | ||
Active bool `json:"active"` | ||
} | ||
|
||
// GetRunInfoExperiment experiment properties | ||
type GetRunInfoExperiment struct { | ||
ID string `json:"id"` | ||
Name string `json:"name"` | ||
} | ||
|
||
// GetRunMetrics is the reponse struct for GetRunMetrics endpoint (slice of RunMetric) | ||
type GetRunMetrics []RunMetrics | ||
|
||
// RunMetrics is one run metrics | ||
type RunMetrics struct { | ||
Name string `json:"name"` | ||
Context map[string]any `json:"context"` | ||
Values []float64 `json:"values"` | ||
Iters []int64 `json:"iters"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package response | ||
|
||
// Success represents the response json in api success | ||
type Success struct { | ||
ID string `json:"id"` | ||
Status string `json:"status"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
//go:build integration | ||
|
||
package run | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/google/uuid" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/suite" | ||
|
||
"github.com/G-Research/fasttrackml/pkg/api/aim/response" | ||
"github.com/G-Research/fasttrackml/pkg/api/mlflow/dao/models" | ||
"github.com/G-Research/fasttrackml/tests/integration/golang/fixtures" | ||
"github.com/G-Research/fasttrackml/tests/integration/golang/helpers" | ||
) | ||
|
||
type GetRunInfoTestSuite struct { | ||
suite.Suite | ||
client *helpers.HttpClient | ||
runFixtures *fixtures.RunFixtures | ||
experimentFixtures *fixtures.ExperimentFixtures | ||
run *models.Run | ||
} | ||
|
||
func TestGetRunInfoTestSuite(t *testing.T) { | ||
suite.Run(t, new(GetRunInfoTestSuite)) | ||
} | ||
|
||
func (s *GetRunInfoTestSuite) SetupTest() { | ||
s.client = helpers.NewAimApiClient(helpers.GetServiceUri()) | ||
|
||
runFixtures, err := fixtures.NewRunFixtures(helpers.GetDatabaseUri()) | ||
assert.Nil(s.T(), err) | ||
s.runFixtures = runFixtures | ||
|
||
expFixtures, err := fixtures.NewExperimentFixtures(helpers.GetDatabaseUri()) | ||
assert.Nil(s.T(), err) | ||
s.experimentFixtures = expFixtures | ||
|
||
exp := &models.Experiment{ | ||
Name: uuid.New().String(), | ||
LifecycleStage: models.LifecycleStageActive, | ||
} | ||
_, err = s.experimentFixtures.CreateExperiment(context.Background(), exp) | ||
assert.Nil(s.T(), err) | ||
|
||
s.run, err = s.runFixtures.CreateExampleRun(context.Background(), exp) | ||
assert.Nil(s.T(), err) | ||
} | ||
|
||
func (s *GetRunInfoTestSuite) Test_Ok() { | ||
defer func() { | ||
assert.Nil(s.T(), s.runFixtures.UnloadFixtures()) | ||
}() | ||
tests := []struct { | ||
name string | ||
runID string | ||
}{ | ||
{ | ||
name: "GetOneRun", | ||
runID: s.run.ID, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
s.T().Run(tt.name, func(T *testing.T) { | ||
var resp response.GetRunInfo | ||
err := s.client.DoGetRequest( | ||
fmt.Sprintf("/runs/%s/info", tt.runID), | ||
&resp, | ||
) | ||
assert.Nil(s.T(), err) | ||
// TODO this assertion fails because ID is not rendered by the endpoint | ||
// assert.Equal(s.T(), s.run.ID, resp.Props.ID) | ||
assert.Equal(s.T(), s.run.Name, resp.Props.Name) | ||
assert.Equal(s.T(), fmt.Sprintf("%v", s.run.ExperimentID), resp.Props.Experiment.ID) | ||
assert.Equal(s.T(), s.run.StartTime.Int64, resp.Props.CreationTime) | ||
assert.Equal(s.T(), s.run.EndTime.Int64, resp.Props.EndTime) | ||
// TODO this assertion fails because tags are not rendered by endpoint | ||
// assert.Equal(s.T(), s.run.Tags[0].Key, resp.Props.Tags[0]) | ||
// TODO this assertion fails so maybe the endpoint is not populating correctly | ||
// assert.NotEmpty(s.T(), resp.Props.CreationTime) | ||
}) | ||
} | ||
} | ||
|
||
func (s *GetRunInfoTestSuite) Test_Error() { | ||
defer func() { | ||
assert.Nil(s.T(), s.runFixtures.UnloadFixtures()) | ||
}() | ||
tests := []struct { | ||
name string | ||
runID string | ||
}{ | ||
{ | ||
name: "GetNonexistentRun", | ||
runID: uuid.NewString(), | ||
}, | ||
} | ||
for _, tt := range tests { | ||
s.T().Run(tt.name, func(T *testing.T) { | ||
var resp response.Error | ||
err := s.client.DoGetRequest( | ||
fmt.Sprintf("/runs/%s/info", tt.runID), | ||
&resp, | ||
) | ||
assert.Nil(s.T(), err) | ||
assert.Equal(s.T(), "Not Found", resp.Message) | ||
}) | ||
} | ||
} |
Oops, something went wrong.