Skip to content
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

Merged
merged 19 commits into from Jan 21, 2024

Conversation

gab-arrobo
Copy link
Collaborator

This PR addresses a few things related to the GO code in the test directory and includes:

  • Remove deprecated io/ioutil package
  • No need of break in switch statement
  • Remove unused functions, variables and values
  • Due to panic, function never reaches return statement, so remove code after panic
  • Use time.NewTicker instead of time.Tick (which leaks the underlying ticker)

@@ -127,8 +127,6 @@ func GetConfig(datapath string, configType uint32) pfcpiface.Conf {
}

panic("Wrong datapath or config type provided")
Copy link
Contributor

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?

Copy link
Collaborator Author

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?

diff --git a/test/integration/conf.go b/test/integration/conf.go
index a6c0d62..e6d3165 100644
--- a/test/integration/conf.go
+++ b/test/integration/conf.go
@@ -6,6 +6,7 @@ package integration
 import (
        "bytes"
        "encoding/json"
+       "fmt"
        "github.com/omec-project/upf-epc/pfcpiface"
        "github.com/sirupsen/logrus"
        "net/http"
@@ -106,27 +107,27 @@ func UP4ConfigWipeOutOnUP4Restart() pfcpiface.Conf {
        return config
 }
 
-func GetConfig(datapath string, configType uint32) pfcpiface.Conf {
+func GetConfig(datapath string, configType uint32) (pfcpiface.Conf, error) {
        switch datapath {
        case DatapathUP4:
                switch configType {
                case ConfigDefault:
-                       return UP4ConfigDefault()
+                       return UP4ConfigDefault(), nil
                case ConfigUPFBasedIPAllocation:
-                       return UP4ConfigUPFBasedIPAllocation()
+                       return UP4ConfigUPFBasedIPAllocation(), nil
                case ConfigWipeOutOnUP4Restart:
-                       return UP4ConfigWipeOutOnUP4Restart()
+                       return UP4ConfigWipeOutOnUP4Restart(), nil
                }
        case DatapathBESS:
                switch configType {
                case ConfigDefault:
-                       return BESSConfigDefault()
+                       return BESSConfigDefault(), nil
                case ConfigUPFBasedIPAllocation:
-                       return BESSConfigUPFBasedIPAllocation()
+                       return BESSConfigUPFBasedIPAllocation(), nil
                }
        }
 
-       panic("Wrong datapath or config type provided")
+       return pfcpiface.Conf{}, fmt.Errorf("wrong datapath or config type provided")
 }
 
 func PushSliceMeterConfig(sliceConfig pfcpiface.NetworkSlice) error {
diff --git a/test/integration/framework.go b/test/integration/framework.go
index ebaef89..bc6f48e 100644
--- a/test/integration/framework.go
+++ b/test/integration/framework.go
@@ -327,21 +327,26 @@ func setup(t *testing.T, configType uint32) {
                MustStartMockUP4()
        }
 
+       getConfig, err := GetConfig(os.Getenv(EnvDatapath), configType)
+       if err != nil {
+               t.Fatal("Wrong datapath or config type provided")
+       }
+
        switch os.Getenv(EnvMode) {
        case ModeDocker:
-               jsonConf, _ := json.Marshal(GetConfig(os.Getenv(EnvDatapath), configType))
+               jsonConf, _ := json.Marshal(getConfig)
                err := os.WriteFile(ConfigPath, jsonConf, os.ModePerm)
                require.NoError(t, err)
                MustStartPFCPAgent()
        case ModeNative:
-               pfcpAgent = pfcpiface.NewPFCPIface(GetConfig(os.Getenv(EnvDatapath), configType))
+               pfcpAgent = pfcpiface.NewPFCPIface(getConfig)
                go pfcpAgent.Run()
        default:
                t.Fatal("Unexpected test mode")
        }
 
        pfcpClient = pfcpsim.NewPFCPClient("127.0.0.1")
-       err := pfcpClient.ConnectN4("127.0.0.1")
+       err = pfcpClient.ConnectN4("127.0.0.1")
        require.NoErrorf(t, err, "failed to connect to UPF")
 
        // wait for PFCP Agent to initialize, blocking

Copy link
Collaborator Author

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?

@@ -246,22 +238,10 @@ func waitForBESSFakeToStart() error {
return waitForPortOpen("tcp", "127.0.0.1", "10514")
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what were these functions used for ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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?

@github-actions
Copy link

This pull request has been stale for 30 days and will be closed in 5 days. Comment to keep it open.

@github-actions
Copy link

This pull request has been stale for 30 days and will be closed in 5 days. Comment to keep it open.

@github-actions
Copy link

This pull request has been stale for 30 days and will be closed in 5 days. Comment to keep it open.

@github-actions
Copy link

This pull request has been stale for 30 days and will be closed in 5 days. Comment to keep it open.

@github-actions
Copy link

This pull request has been stale for 30 days and will be closed in 5 days. Comment to keep it open.

@gab-arrobo
Copy link
Collaborator Author

@dependabot rebase

Copy link

This pull request has been stale for 30 days and will be closed in 5 days. Comment to keep it open.

Copy link

This pull request has been stale for 30 days and will be closed in 5 days. Comment to keep it open.

@gab-arrobo gab-arrobo merged commit a05c20a into omec-project:master Jan 21, 2024
11 checks passed
@gab-arrobo gab-arrobo deleted the test-go-updates branch January 21, 2024 04:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants