Skip to content

Commit

Permalink
server: use unbuffered memory connections for testing, which seem to …
Browse files Browse the repository at this point in the history
…be more robust (#4266)
  • Loading branch information
nicks committed Mar 3, 2021
1 parent 506548d commit a267905
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 24 deletions.
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -69,7 +69,7 @@ require (
github.com/tilt-dev/go-get v0.0.0-20200911222649-1acd29546527
github.com/tilt-dev/localregistry-go v0.0.0-20200615231835-07e386f4ebd7
github.com/tilt-dev/probe v0.2.0
github.com/tilt-dev/tilt-apiserver v0.2.1
github.com/tilt-dev/tilt-apiserver v0.2.2
github.com/tilt-dev/wmclient v0.0.0-20201109174454-1839d0355fbc
github.com/tonistiigi/units v0.0.0-20180711220420-6950e57a87ea
github.com/whilp/git-urls v0.0.0-20160530060445-31bac0d230fa
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Expand Up @@ -1237,8 +1237,8 @@ github.com/tilt-dev/opencensus-go v0.22.5-0.20200904175236-275b1754f353 h1:lxM1v
github.com/tilt-dev/opencensus-go v0.22.5-0.20200904175236-275b1754f353/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
github.com/tilt-dev/probe v0.2.0 h1:2kLs+xNjv6OYoR7OLCQELV6+/Ce0gqOC856qKfN/TB4=
github.com/tilt-dev/probe v0.2.0/go.mod h1:N4FSqESyYQuc9GwIaIoHS5cIUDznIUwDkG6y4kQVXQY=
github.com/tilt-dev/tilt-apiserver v0.2.1 h1:mt5XZ0g4TYiOB8jtMIsBFwBlOl7MgGZqzsP5maJBdz8=
github.com/tilt-dev/tilt-apiserver v0.2.1/go.mod h1:5JegGavWDV+CrTD1w9QWFekMQwctZmbkQumHd4aqsT8=
github.com/tilt-dev/tilt-apiserver v0.2.2 h1:ZzMjWH/oZCpqc294/SocHMm872n9BLZETBAEze8Kz1g=
github.com/tilt-dev/tilt-apiserver v0.2.2/go.mod h1:5JegGavWDV+CrTD1w9QWFekMQwctZmbkQumHd4aqsT8=
github.com/tilt-dev/wmclient v0.0.0-20201109174454-1839d0355fbc h1:wGkAoZhrvnmq93B4W2v+agiPl7xzqUaxXkxmKrwJ6bc=
github.com/tilt-dev/wmclient v0.0.0-20201109174454-1839d0355fbc/go.mod h1:n01fG3LbImzxBP3GGCTHkgXuPeJusWg6xv0QYGm9HtE=
github.com/timakin/bodyclose v0.0.0-20190930140734-f7f2e9bca95e/go.mod h1:Qimiffbc6q9tBWlVV6x0P9sat/ao1xEkREYPPj9hphk=
Expand Down
3 changes: 1 addition & 2 deletions internal/engine/upper_test.go
Expand Up @@ -17,7 +17,6 @@ import (
"testing"
"time"

"github.com/akutz/memconn"
"github.com/docker/distribution/reference"
dockertypes "github.com/docker/docker/api/types"
"github.com/google/uuid"
Expand Down Expand Up @@ -3764,7 +3763,7 @@ func newTestFixture(t *testing.T) *testFixture {
dcw := dcwatch.NewEventWatcher(fakeDcc, dockerClient)
dclm := runtimelog.NewDockerComposeLogManager(fakeDcc)
pm := NewProfilerManager()
serverOptions, err := server.ProvideTiltServerOptions(ctx, "localhost", 0, model.TiltBuild{}, &memconn.Provider{})
serverOptions, err := server.ProvideTiltServerOptions(ctx, "localhost", 0, model.TiltBuild{}, server.ProvideMemConn())
require.NoError(t, err)
hudsc := server.ProvideHeadsUpServerController(0, serverOptions, &server.HeadsUpServer{}, assets.NewFakeServer(), model.WebURL{})
ewm := k8swatch.NewEventWatchManager(kCli, of, ns)
Expand Down
6 changes: 3 additions & 3 deletions internal/hud/server/apiserver.go
Expand Up @@ -24,12 +24,12 @@ type APIServerConfig = apiserver.Config
type DynamicInterface = dynamic.Interface
type Interface = tiltapi.Interface

func ProvideMemConn() *memconn.Provider {
return &memconn.Provider{}
func ProvideMemConn() apiserver.ConnProvider {
return apiserver.NetworkConnProvider(&memconn.Provider{}, "memu")
}

// Configures the Tilt API server.
func ProvideTiltServerOptions(ctx context.Context, host model.WebHost, port model.WebPort, tiltBuild model.TiltBuild, memconn *memconn.Provider) (*APIServerConfig, error) {
func ProvideTiltServerOptions(ctx context.Context, host model.WebHost, port model.WebPort, tiltBuild model.TiltBuild, memconn apiserver.ConnProvider) (*APIServerConfig, error) {
w := logger.Get(ctx).Writer(logger.DebugLvl)
builder := builder.NewServerBuilder().
WithOutputWriter(w)
Expand Down
21 changes: 17 additions & 4 deletions internal/hud/server/apiserver_test.go
Expand Up @@ -7,12 +7,12 @@ import (
"strings"
"testing"

"github.com/akutz/memconn"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/watch"

"github.com/tilt-dev/tilt-apiserver/pkg/server/builder/resource"

Expand All @@ -26,7 +26,7 @@ import (
// Ensure creating objects works with the dynamic API clients.
func TestAPIServer(t *testing.T) {
ctx, _, _ := testutils.CtxAndAnalyticsForTest()
memconn := &memconn.Provider{}
memconn := ProvideMemConn()
cfg, err := ProvideTiltServerOptions(ctx, "localhost", 0, model.TiltBuild{}, memconn)
require.NoError(t, err)

Expand Down Expand Up @@ -76,12 +76,13 @@ type typedTestCase struct {
Name string
Create func(ctx context.Context, name string, annotations map[string]string) error
Get func(ctx context.Context, name string) (resource.Object, error)
Watch func(ctx context.Context) (watch.Interface, error)
}

// Ensure creating objects works with the typed API clients.
func TestAPIServerTypedClient(t *testing.T) {
ctx, _, _ := testutils.CtxAndAnalyticsForTest()
memconn := &memconn.Provider{}
memconn := ProvideMemConn()
cfg, err := ProvideTiltServerOptions(ctx, "localhost", 0, model.TiltBuild{}, memconn)
require.NoError(t, err)

Expand All @@ -108,13 +109,20 @@ func TestAPIServerTypedClient(t *testing.T) {
Get: func(ctx context.Context, name string) (resource.Object, error) {
return clientset.CoreV1alpha1().FileWatches().Get(ctx, name, metav1.GetOptions{})
},
Watch: func(ctx context.Context) (watch.Interface, error) {
return clientset.CoreV1alpha1().FileWatches().Watch(ctx, metav1.ListOptions{})
},
},
}

for _, testCase := range testCases {
t.Run(testCase.Name, func(t *testing.T) {
objName := fmt.Sprintf("typed-%s", strings.ToLower(testCase.Name))
err := testCase.Create(ctx, objName, map[string]string{
watcher, err := testCase.Watch(ctx)
require.NoError(t, err)
defer watcher.Stop()

err = testCase.Create(ctx, objName, map[string]string{
"my-random-key": "my-random-value",
})
require.NoError(t, err)
Expand All @@ -127,6 +135,11 @@ func TestAPIServerTypedClient(t *testing.T) {

assert.Equal(t, objName, metadata.GetName())
assert.Equal(t, "my-random-value", metadata.GetAnnotations()["my-random-key"])

watchEvent := <-watcher.ResultChan()
watchedMetadata, err := meta.Accessor(watchEvent.Object)
require.NoError(t, err)
assert.Equal(t, objName, watchedMetadata.GetName())
})
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Expand Up @@ -518,7 +518,7 @@ github.com/tilt-dev/localregistry-go
## explicit
github.com/tilt-dev/probe/pkg/probe
github.com/tilt-dev/probe/pkg/prober
# github.com/tilt-dev/tilt-apiserver v0.2.1
# github.com/tilt-dev/tilt-apiserver v0.2.2
## explicit
github.com/tilt-dev/tilt-apiserver/pkg/server/apiserver
github.com/tilt-dev/tilt-apiserver/pkg/server/builder
Expand Down

0 comments on commit a267905

Please sign in to comment.