Skip to content

Commit 9df6cf8

Browse files
mustard-mhroboquat
authored andcommitted
[supervisor] fix order change in config only not works
1 parent f597a96 commit 9df6cf8

File tree

2 files changed

+84
-5
lines changed

2 files changed

+84
-5
lines changed

components/supervisor/pkg/ports/ports.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ func (pm *Manager) updateState(ctx context.Context, exposed []ExposedPort, serve
291291
stateChanged := !reflect.DeepEqual(newState, pm.state)
292292
pm.state = newState
293293

294-
if !stateChanged {
294+
if !stateChanged && configured == nil {
295295
return
296296
}
297297

components/supervisor/pkg/ports/ports_test.go

Lines changed: 83 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ func TestPortsUpdateState(t *testing.T) {
168168
{LocalPort: 60000},
169169
},
170170
ExpectedUpdates: UpdateExpectation{
171+
{},
171172
{},
172173
[]*api.PortsStatus{{LocalPort: 4040, Served: true, OnOpen: api.PortsStatus_open_browser}},
173174
[]*api.PortsStatus{{LocalPort: 4040, Served: true, OnOpen: api.PortsStatus_open_browser, Exposed: &api.ExposedPortInfo{Visibility: api.PortVisibility_public, Url: "4040-foobar", OnExposed: api.OnPortExposedAction_open_browser}}},
@@ -234,8 +235,8 @@ func TestPortsUpdateState(t *testing.T) {
234235
ExpectedUpdates: UpdateExpectation{
235236
{},
236237
{
237-
{LocalPort: 8080, Served: true, OnOpen: api.PortsStatus_notify_private},
238238
{LocalPort: 3000, Served: true, OnOpen: api.PortsStatus_notify_private},
239+
{LocalPort: 8080, Served: true, OnOpen: api.PortsStatus_notify_private},
239240
},
240241
},
241242
},
@@ -496,6 +497,86 @@ func TestPortsUpdateState(t *testing.T) {
496497
{{LocalPort: 3000, Name: "react", Served: true, OnOpen: api.PortsStatus_notify, Exposed: &api.ExposedPortInfo{Visibility: api.PortVisibility_private, OnExposed: api.OnPortExposedAction_notify, Url: "foobar"}}},
497498
},
498499
},
500+
{
501+
Desc: "change configed ports order",
502+
Changes: []Change{
503+
{
504+
Config: &ConfigChange{instance: []*gitpod.PortsItems{
505+
{Port: 3001, Visibility: "private", Name: "react"},
506+
{Port: 3000, Visibility: "private", Name: "react"},
507+
}},
508+
},
509+
{
510+
Config: &ConfigChange{instance: []*gitpod.PortsItems{
511+
{Port: "5000-5999", Visibility: "private", Name: "react"},
512+
{Port: 3001, Visibility: "private", Name: "react"},
513+
{Port: 3000, Visibility: "private", Name: "react"},
514+
}},
515+
},
516+
{
517+
Served: []ServedPort{{net.IPv4zero, 5002, false}},
518+
},
519+
{
520+
Served: []ServedPort{{net.IPv4zero, 5002, false}, {net.IPv4zero, 5001, false}},
521+
},
522+
{
523+
Config: &ConfigChange{instance: []*gitpod.PortsItems{
524+
{Port: 3000, Visibility: "private", Name: "react"},
525+
{Port: 3001, Visibility: "private", Name: "react"},
526+
}},
527+
},
528+
{
529+
Served: []ServedPort{{net.IPv4zero, 5001, false}, {net.IPv4zero, 3000, false}},
530+
},
531+
{
532+
Exposed: []ExposedPort{{LocalPort: 3000, Public: false, URL: "foobar"}},
533+
},
534+
},
535+
ExpectedExposure: []ExposedPort{
536+
{LocalPort: 5002},
537+
{LocalPort: 5001},
538+
{LocalPort: 3000},
539+
{LocalPort: 3001},
540+
},
541+
ExpectedUpdates: UpdateExpectation{
542+
{},
543+
{
544+
{LocalPort: 3001, Name: "react", OnOpen: api.PortsStatus_notify},
545+
{LocalPort: 3000, Name: "react", OnOpen: api.PortsStatus_notify},
546+
},
547+
{
548+
{LocalPort: 3001, Name: "react", OnOpen: api.PortsStatus_notify},
549+
{LocalPort: 3000, Name: "react", OnOpen: api.PortsStatus_notify},
550+
},
551+
{
552+
{LocalPort: 5002, Name: "react", Served: true, OnOpen: api.PortsStatus_notify},
553+
{LocalPort: 3001, Name: "react", OnOpen: api.PortsStatus_notify},
554+
{LocalPort: 3000, Name: "react", OnOpen: api.PortsStatus_notify},
555+
},
556+
{
557+
{LocalPort: 5001, Name: "react", Served: true, OnOpen: api.PortsStatus_notify},
558+
{LocalPort: 5002, Name: "react", Served: true, OnOpen: api.PortsStatus_notify},
559+
{LocalPort: 3001, Name: "react", OnOpen: api.PortsStatus_notify},
560+
{LocalPort: 3000, Name: "react", OnOpen: api.PortsStatus_notify},
561+
},
562+
{
563+
{LocalPort: 3000, Name: "react", OnOpen: api.PortsStatus_notify},
564+
{LocalPort: 3001, Name: "react", OnOpen: api.PortsStatus_notify},
565+
{LocalPort: 5001, Served: true, OnOpen: api.PortsStatus_notify_private},
566+
{LocalPort: 5002, Served: true, OnOpen: api.PortsStatus_notify_private},
567+
},
568+
{
569+
{LocalPort: 3000, Name: "react", Served: true, OnOpen: api.PortsStatus_notify},
570+
{LocalPort: 3001, Name: "react", OnOpen: api.PortsStatus_notify},
571+
{LocalPort: 5001, Served: true, OnOpen: api.PortsStatus_notify_private},
572+
},
573+
{
574+
{LocalPort: 3000, Name: "react", Served: true, OnOpen: api.PortsStatus_notify, Exposed: &api.ExposedPortInfo{Visibility: api.PortVisibility_private, OnExposed: api.OnPortExposedAction_notify, Url: "foobar"}},
575+
{LocalPort: 3001, Name: "react", OnOpen: api.PortsStatus_notify},
576+
{LocalPort: 5001, Served: true, OnOpen: api.PortsStatus_notify_private},
577+
},
578+
},
579+
},
499580
}
500581

501582
log.Log.Logger.SetLevel(logrus.FatalLevel)
@@ -584,8 +665,6 @@ func TestPortsUpdateState(t *testing.T) {
584665
wg.Wait()
585666

586667
var (
587-
sorPorts = cmpopts.SortSlices(func(x, y uint32) bool { return x < y })
588-
sortPortStatus = cmpopts.SortSlices(func(x, y *api.PortsStatus) bool { return x.LocalPort < y.LocalPort })
589668
sortExposed = cmpopts.SortSlices(func(x, y ExposedPort) bool { return x.LocalPort < y.LocalPort })
590669
ignoreUnexported = cmpopts.IgnoreUnexported(
591670
api.PortsStatus{},
@@ -596,7 +675,7 @@ func TestPortsUpdateState(t *testing.T) {
596675
t.Errorf("unexpected exposures (-want +got):\n%s", diff)
597676
}
598677

599-
if diff := cmp.Diff(test.ExpectedUpdates, UpdateExpectation(updts), sorPorts, sortPortStatus, ignoreUnexported); diff != "" {
678+
if diff := cmp.Diff(test.ExpectedUpdates, UpdateExpectation(updts), ignoreUnexported); diff != "" {
600679
t.Errorf("unexpected updates (-want +got):\n%s", diff)
601680
}
602681
})

0 commit comments

Comments
 (0)