Skip to content

Commit

Permalink
review addressed
Browse files Browse the repository at this point in the history
  • Loading branch information
amrita-shrestha committed Feb 4, 2025
1 parent 7505110 commit 43c5a2e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 22 deletions.
28 changes: 16 additions & 12 deletions tests/ociswrapper/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,22 +125,26 @@ Also, see `./bin/ociswrapper help` for more information.
- `200 OK` - oCIS server is stopped
- `500 Internal Server Error` - Unable to stop oCIS server

6. `POST /services/{service-name}`
6. `POST /services/{service-name}`

Restart oCIS with service excluded and start excluded oCIS service individually, not covered by the oCIS supervisor.
Restart oCIS with service excluded and start excluded oCIS service individually, not covered by the oCIS supervisor.

Body of the request should be a JSON object with the following structure:
Body of the request should be a JSON object with the following structure:

```json
{
"ENV_KEY1": "value1",
"ENV_KEY2": "value2"
}
```

```json
{
"ENV_KEY1": "value1",
"ENV_KEY2": "value2"
}
```
> **⚠️ Note:**
>
> You need to set the proper addresses to access the service from other steps in the CI pipeline.
>
> `{SERVICE-NAME}_DEBUG_ADDR=0.0.0.0:{DEBUG_PORT}`
> `{SERVICE-NAME}_HTTP_ADDR=0.0.0.0:{HTTP_PORT}`

> **⚠️ WARNING:**
> You need to set the address of the debug server to expose the port in CI
> `{SERVICE-NAME}_DEBUG_ADDR`

Returns:

Expand Down
4 changes: 2 additions & 2 deletions tests/ociswrapper/ocis/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ func Get(key string) string {
return config[key]
}

func SetService(key string, value int) {
func SetServiceDebugPort(key string, value int) {
services[key] = value
}

func GetService(key string) int {
func GetServiceDebugPort(key string) int {
return services[key]
}
11 changes: 5 additions & 6 deletions tests/ociswrapper/ocis/ocis.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var EnvConfigs = []string{}
var runningServices = make(map[string]int)

func Start(envMap []string) {
log.Println("Starting oCIS service........")
log.Println("Starting oCIS service...")
StartService("", envMap)
}

Expand Down Expand Up @@ -328,13 +328,13 @@ func StopService(service string) (bool, string) {
return true, fmt.Sprintf("Service %s stopped successfully", service)
}

// WaitUntilPortListens waits until the port for a given service is listening
func WaitUntilPortListens(service string) bool {
// wait until the port for a given service is listening
func WaitForService(service string) bool {
overallTimeout := time.After(30 * time.Second)
ticker := time.NewTicker(2 * time.Second)
defer ticker.Stop()

port := config.GetService(service)
port := config.GetServiceDebugPort(service)

for {
select {
Expand All @@ -349,7 +349,6 @@ func WaitUntilPortListens(service string) bool {
continue
}

// Check if the port is listening
address := fmt.Sprintf(":%d", port)
// Try to connect to the port
conn, err := net.DialTimeout("tcp", address, 1*time.Second)
Expand All @@ -358,7 +357,7 @@ func WaitUntilPortListens(service string) bool {
log.Println(fmt.Sprintf("%s service is ready to listen port %d", service, port))
return true
}
log.Println(fmt.Sprintf("%v port is not ready %v\n", conn, err))
log.Println(fmt.Sprintf("%s service is not ready on port %v. %v\n", service, port, err))
}
}
}
4 changes: 2 additions & 2 deletions tests/ociswrapper/wrapper/handlers/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func OcisServiceHandler(res http.ResponseWriter, req *http.Request) {
if strings.HasSuffix(key, "DEBUG_ADDR") {
address := strings.Split(value.(string), ":")
port, _ := strconv.Atoi(address[1])
config.SetService(serviceName, port)
config.SetServiceDebugPort(serviceName, port)
}
}

Expand All @@ -240,7 +240,7 @@ func OcisServiceHandler(res http.ResponseWriter, req *http.Request) {
common.Wg.Add(1)
go ocis.StartService(serviceName, serviceEnvMap)

success := ocis.WaitUntilPortListens(serviceName)
success := ocis.WaitForService(serviceName)
if success {
log.Println(fmt.Sprintf("Found Port for %s......", serviceName))
sendResponse(res, http.StatusOK, fmt.Sprintf("oCIS service %s started successfully", serviceName))
Expand Down

0 comments on commit 43c5a2e

Please sign in to comment.