Skip to content

Commit ed6eb4e

Browse files
committed
fix: e2e test
1 parent d544fa3 commit ed6eb4e

File tree

1 file changed

+33
-21
lines changed

1 file changed

+33
-21
lines changed

integration/kube_integration_test.go

+33-21
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import (
3434
"os/user"
3535
"strconv"
3636
"strings"
37-
"sync"
3837
"testing"
3938
"time"
4039

@@ -2217,13 +2216,17 @@ func testKubeJoin(t *testing.T, suite *KubeSuite) {
22172216
require.NoError(t, err)
22182217
participantStdoutR, participantStdoutW, err := os.Pipe()
22192218
require.NoError(t, err)
2220-
streamsMu := &sync.Mutex{}
2221-
streams := make([]*client.KubeSession, 0, 3)
2222-
observerCaptures := make([]*bytes.Buffer, 0, 2)
2219+
2220+
observerCaptures := make([]*bytes.Buffer, 2)
22232221
albProxy := helpers.MustStartMockALBProxy(t, teleport.Config.Proxy.WebAddr.Addr)
22242222

22252223
// join peer by KubeProxyAddr
22262224
group.Go(func() error {
2225+
defer func() {
2226+
// close participant stdout so that we can read it after till EOF
2227+
participantStdoutW.Close()
2228+
}()
2229+
22272230
tc, err := teleport.NewClient(helpers.ClientConfig{
22282231
Login: hostUsername,
22292232
Cluster: helpers.Site,
@@ -2245,43 +2248,52 @@ func testKubeJoin(t *testing.T, suite *KubeSuite) {
22452248
if err != nil {
22462249
return trace.Wrap(err)
22472250
}
2248-
streamsMu.Lock()
2249-
streams = append(streams, stream)
2250-
streamsMu.Unlock()
2251+
22512252
stream.Wait()
2252-
// close participant stdout so that we can read it after till EOF
2253-
participantStdoutW.Close()
2253+
2254+
if err := stream.Detach(); err != nil && !terminal.IsOKWebsocketCloseError(err) {
2255+
return trace.Wrap(err)
2256+
}
2257+
22542258
return nil
22552259
})
22562260

22572261
// join observer by WebProxyAddr
22582262
group.Go(func() error {
22592263
stream, capture := kubeJoinByWebAddr(t, teleport, participantUsername, kubeUsers, kubeGroups)
2260-
streamsMu.Lock()
2261-
streams = append(streams, stream)
2262-
observerCaptures = append(observerCaptures, capture)
2263-
streamsMu.Unlock()
2264+
observerCaptures[0] = capture
22642265
stream.Wait()
2266+
2267+
if err := stream.Detach(); err != nil && !terminal.IsOKWebsocketCloseError(err) {
2268+
return trace.Wrap(err)
2269+
}
2270+
22652271
return nil
22662272
})
22672273

22682274
// join observer with ALPN conn upgrade
22692275
group.Go(func() error {
22702276
stream, capture := kubeJoinByALBAddr(t, teleport, participantUsername, kubeUsers, kubeGroups, albProxy.Addr().String())
2271-
streamsMu.Lock()
2272-
streams = append(streams, stream)
2273-
observerCaptures = append(observerCaptures, capture)
2274-
streamsMu.Unlock()
2277+
observerCaptures[1] = capture
22752278
stream.Wait()
2279+
2280+
if err := stream.Detach(); err != nil && !terminal.IsOKWebsocketCloseError(err) {
2281+
return trace.Wrap(err)
2282+
}
22762283
return nil
22772284
})
22782285

22792286
// We wait again for the second user to finish joining the session.
2280-
// We allow a bit of time to pass here to give the session manager time to recognize the
2281-
// new IO streams of the second client.
2282-
time.Sleep(time.Second * 5)
2287+
require.EventuallyWithT(t, func(t *assert.CollectT) {
2288+
session, err := teleport.Process.GetAuthServer().GetSessionTracker(context.Background(), session.GetName())
2289+
if !assert.NoError(t, err) {
2290+
return
2291+
}
2292+
2293+
assert.Len(t, session.GetParticipants(), 2)
2294+
}, 15*time.Second, 500*time.Millisecond)
22832295

2284-
// sent a test message from the participant
2296+
// send a test message from the participant
22852297
participantStdinW.Write([]byte("\ahi from peer\n\r"))
22862298

22872299
// lets type "echo hi" followed by "enter" and then "exit" + "enter":

0 commit comments

Comments
 (0)