Skip to content

Commit

Permalink
Fix RefreshConfig (flyteorg#139)
Browse files Browse the repository at this point in the history
* Fix RefreshConfig
* RefreshConfig unit test

Signed-off-by: iaroslav-ciupin <[email protected]>
  • Loading branch information
iaroslav-ciupin authored Aug 16, 2022
1 parent bcfa537 commit 65025fd
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
38 changes: 36 additions & 2 deletions storage/protobuf_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ import (
"fmt"
"io"
"math/rand"
"net/http"
"net/http/httptest"
"testing"

"github.com/flyteorg/flytestdlib/promutils"

"github.com/flyteorg/stow/s3"
"github.com/golang/protobuf/proto"
errs "github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/flyteorg/flytestdlib/promutils"
)

type mockProtoMessage struct {
Expand Down Expand Up @@ -57,6 +61,36 @@ func TestDefaultProtobufStore(t *testing.T) {
assert.Equal(t, int64(5), m.X)
})

t.Run("RefreshConfig", func(t *testing.T) {
testScope := promutils.NewTestScope()
s, err := NewDataStore(&Config{Type: TypeMemory}, testScope)
require.NoError(t, err)
require.IsType(t, DefaultProtobufStore{}, s.ComposedProtobufStore)
require.IsType(t, &InMemoryStore{}, s.ComposedProtobufStore.(DefaultProtobufStore).RawStore)

oldMetrics := s.metrics
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
}))
defer server.Close()

err = s.RefreshConfig(&Config{
Type: TypeMinio,
Stow: StowConfig{
Kind: TypeS3,
Config: map[string]string{
s3.ConfigAccessKeyID: "key",
s3.ConfigSecretKey: "sec",
s3.ConfigEndpoint: server.URL,
}},
InitContainer: "b"})

assert.NoError(t, err)
require.IsType(t, DefaultProtobufStore{}, s.ComposedProtobufStore)
assert.IsType(t, &StowStore{}, s.ComposedProtobufStore.(DefaultProtobufStore).RawStore)
assert.Equal(t, oldMetrics, s.metrics)
})

t.Run("invalid type", func(t *testing.T) {
testScope := promutils.NewTestScope()

Expand Down
1 change: 1 addition & 0 deletions storage/rawstores.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ func (ds *DataStore) RefreshConfig(cfg *Config) error {
rawStore = newCachedRawStore(cfg, rawStore, ds.metrics.cacheMetrics)
protoStore := NewDefaultProtobufStore(rawStore, ds.metrics.protoMetrics)
newDS := NewCompositeDataStore(NewURLPathConstructor(), protoStore)
newDS.metrics = ds.metrics
*ds = *newDS
return nil
}

0 comments on commit 65025fd

Please sign in to comment.