Skip to content

Commit

Permalink
Use service ports outside of the local port range
Browse files Browse the repository at this point in the history
  • Loading branch information
Danielius1922 committed Aug 15, 2024
1 parent c56a876 commit 4f99d57
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 30 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ jobs:
echo "Number of cores: $(nproc)"
echo "Number of threads: $(nproc --all)"
cat /proc/sys/net/ipv4/ip_local_port_range
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4
with:
Expand Down
6 changes: 3 additions & 3 deletions device-provisioning-service/service/provision_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import (
)

const (
DPSCoapGwHost = "127.0.0.1:40002"
DPSCoapGwHost = "127.0.0.1:20132"
DPSHost = "127.0.0.1:20030"
)

Expand Down Expand Up @@ -445,10 +445,10 @@ func TestProvisioningFromNewDPSAddress(t *testing.T) {
_, shutdownSim := test.OnboardDpsSim(ctx, t, c, deviceID, dpsCfg.APIs.COAP.Addr, test.TestDevsimResources)
defer shutdownSim()

// change DPS to new address from "127.0.0.1:40030" to "127.0.0.1:50030" and restart DPS
// change DPS to new address from "127.0.0.1:20130" to "127.0.0.1:20230" and restart DPS
deferedDpsCleanUp = false
dpsShutDown()
dpsCfg.APIs.COAP.Addr = "127.0.0.1:50030"
dpsCfg.APIs.COAP.Addr = "127.0.0.1:20230"
h := newTestRequestHandler(t, dpsCfg, defaultTestDpsHandlerConfig())
h.StartDps(service.WithRequestHandler(h))
defer h.StopDps()
Expand Down
4 changes: 2 additions & 2 deletions device-provisioning-service/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ import (
)

const (
DPSHost = "127.0.0.1:40030"
DPSHTTPHost = "127.0.0.1:40031"
DPSHost = "127.0.0.1:20130"
DPSHTTPHost = "127.0.0.1:20131"
DPSEnrollmentGroupID = "6aa1aa8e-2b91-48ee-bfbc-a4e22d8e20d8"
DPSOwner = "1"
)
Expand Down
11 changes: 0 additions & 11 deletions pkg/net/coap/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
"os/exec"
"strings"

coapDtlsServer "github.com/plgd-dev/go-coap/v3/dtls/server"
Expand Down Expand Up @@ -50,16 +49,6 @@ func closeOnError(services []service.APIService, logger log.Logger) {
}
}

func listPorts() {
cmd := exec.Command("/usr/bin/netstat", "-tulpn")
stdout, err := cmd.Output()
if err != nil {
fmt.Println(err.Error())
} else {
fmt.Println(string(stdout))
}
}

func newService(protocol Protocol, config Config, serviceOpts Options, fileWatcher *fsnotify.Watcher, logger log.Logger, opts ...interface {
coapTcpServer.Option
coapDtlsServer.Option
Expand Down
1 change: 0 additions & 1 deletion pkg/net/coap/service/tcpServer.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ func newTCPServer(config Config, serviceOpts Options, fileWatcher *fsnotify.Watc
) (*tcpServer, error) {
listener, closeListener, err := newTCPListener(config, serviceOpts, fileWatcher, logger)
if err != nil {
listPorts()
return nil, fmt.Errorf("cannot create listener: %w", err)
}
fmt.Printf("tcp listerer(%v) opened\n", config.Addr)
Expand Down
2 changes: 0 additions & 2 deletions pkg/net/coap/service/udpServer.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ func newDTLSServer(config Config, serviceOpts Options, fileWatcher *fsnotify.Wat
) (*dtlsServer, error) {
listener, closeListener, err := newDTLSListener(config, serviceOpts, fileWatcher, logger)
if err != nil {
listPorts()
return nil, fmt.Errorf("cannot create listener: %w", err)
}
fmt.Printf("dtls listerer(%v) opened\n", config.Addr)
Expand Down Expand Up @@ -177,7 +176,6 @@ func newUDPServer(config Config, serviceOpts Options, logger log.Logger, opts ..
) (*udpServer, error) {
listener, closeListener, err := newUDPListener(config, logger)
if err != nil {
listPorts()
return nil, fmt.Errorf("cannot create listener: %w", err)
}
fmt.Printf("udp listerer(%v) opened\n", config.Addr)
Expand Down
11 changes: 0 additions & 11 deletions test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1038,16 +1038,6 @@ func (ls *ListenSocket) IsClosed() (bool, error) {

type ListenSockets []ListenSocket

func listPorts() {
cmd := exec.Command("/usr/bin/netstat", "-tulpn")
stdout, err := cmd.Output()
if err != nil {
fmt.Println(err.Error())
} else {
fmt.Println(string(stdout))
}
}

func (ls ListenSockets) CheckForClosedSockets() error {
// wait for all sockets to be closed - max 3 minutes = 900*200
socketClosed := make([]bool, len(ls))
Expand All @@ -1073,7 +1063,6 @@ func (ls ListenSockets) CheckForClosedSockets() error {
if allClosed {
return nil
}
listPorts()
time.Sleep(time.Millisecond * 200)
}
return errors.New("ports not closed")
Expand Down

0 comments on commit 4f99d57

Please sign in to comment.