-
Notifications
You must be signed in to change notification settings - Fork 103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Go updates for the test directory #658
Changes from 9 commits
e9df6a5
c4deb4a
f5dddd4
0b99915
61a00cf
0394ef4
2ebaa22
4c5cfd3
e1605af
6d19274
4f386fd
601f09b
13744c6
1669b8b
5b2a6dc
a06b76f
77576bf
a2fb993
1241092
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,6 @@ import ( | |
"github.com/sirupsen/logrus" | ||
"github.com/stretchr/testify/require" | ||
"github.com/wmnsk/go-pfcp/ie" | ||
"io/ioutil" | ||
"net" | ||
"os" | ||
"testing" | ||
|
@@ -42,8 +41,6 @@ const ( | |
ModeDocker = "docker" | ||
ModeNative = "native" | ||
|
||
defaultSliceID = 0 | ||
|
||
defaultSDFFilter = "permit out udp from any to assigned 80-80" | ||
|
||
ueAddress = "17.0.0.1" | ||
|
@@ -167,11 +164,6 @@ func init() { | |
providers.MustCreateNetworkIfNotExists(DockerTestNetwork) | ||
} | ||
|
||
func (af appFilter) isEmpty() bool { | ||
return af.proto == 0 && len(af.appIP) == 0 && | ||
af.appPort.low == 0 && af.appPort.high == 0 | ||
} | ||
|
||
func IsConnectionOpen(network string, host string, port string) bool { | ||
target := net.JoinHostPort(host, port) | ||
|
||
|
@@ -199,14 +191,14 @@ func IsConnectionOpen(network string, host string, port string) bool { | |
|
||
func waitForPortOpen(net string, host string, port string) error { | ||
timeout := time.After(5 * time.Second) | ||
ticker := time.Tick(500 * time.Millisecond) | ||
ticker := time.NewTicker(500 * time.Millisecond) | ||
|
||
// Keep trying until we're timed out or get a result/error | ||
for { | ||
select { | ||
case <-timeout: | ||
return errors.New("timed out") | ||
case <-ticker: | ||
case <-ticker.C: | ||
if IsConnectionOpen(net, host, port) { | ||
return nil | ||
} | ||
|
@@ -218,7 +210,7 @@ func waitForPortOpen(net string, host string, port string) error { | |
// It retries every 1.5 seconds (0.5 seconds of interval between tries + 1 seconds that PFCP Client waits for response). | ||
func waitForPFCPAssociationSetup(pfcpClient *pfcpsim.PFCPClient) error { | ||
timeout := time.After(30 * time.Second) | ||
ticker := time.Tick(500 * time.Millisecond) | ||
ticker := time.NewTicker(500 * time.Millisecond) | ||
|
||
// Decrease timeout to wait for PFCP responses. | ||
// This decreases time to wait for PFCP Agent to start. | ||
|
@@ -229,7 +221,7 @@ func waitForPFCPAssociationSetup(pfcpClient *pfcpsim.PFCPClient) error { | |
select { | ||
case <-timeout: | ||
return errors.New("timed out") | ||
case <-ticker: | ||
case <-ticker.C: | ||
// each test case requires PFCP Association, so we don't teardown it once we notice it's established. | ||
if err := pfcpClient.SetupAssociation(); err == nil { | ||
return nil | ||
|
@@ -246,22 +238,10 @@ func waitForBESSFakeToStart() error { | |
return waitForPortOpen("tcp", "127.0.0.1", "10514") | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what were these functions used for ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not know if these functions were used at any point in the past. Currently, they are not use anywhere in the code. So, I do not know what they were used for. What do you think about removing them? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @badhrinathpa, or would you prefer that the unused code stays in the repo? If so, I can add a "nolint:unused" comment? |
||
func isModeNative() bool { | ||
return os.Getenv(EnvMode) == ModeNative | ||
} | ||
|
||
func isModeDocker() bool { | ||
return os.Getenv(EnvMode) == ModeDocker | ||
} | ||
|
||
func isDatapathUP4() bool { | ||
return os.Getenv(EnvDatapath) == DatapathUP4 | ||
} | ||
|
||
func isDatapathBESS() bool { | ||
return os.Getenv(EnvDatapath) == DatapathBESS | ||
} | ||
|
||
func initForwardingPipelineConfig() { | ||
p4rtClient, err := providers.ConnectP4rt("127.0.0.1:50001", true) | ||
if err != nil { | ||
|
@@ -350,7 +330,7 @@ func setup(t *testing.T, configType uint32) { | |
switch os.Getenv(EnvMode) { | ||
case ModeDocker: | ||
jsonConf, _ := json.Marshal(GetConfig(os.Getenv(EnvDatapath), configType)) | ||
err := ioutil.WriteFile(ConfigPath, jsonConf, os.ModePerm) | ||
err := os.WriteFile(ConfigPath, jsonConf, os.ModePerm) | ||
require.NoError(t, err) | ||
MustStartPFCPAgent() | ||
case ModeNative: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we return some error instead than panic?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the
panic
was originally added to stop the test and avoid it to keep running. Below is a way to avoid the panic. What do you think?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@badhrinathpa, any comment on this?