Skip to content

Commit

Permalink
fix: Modify minimum duration param type to time.Duration
Browse files Browse the repository at this point in the history
Modify minimum duration param type of CheckMinInterval func to time.Duration.

Signed-off-by: Lindsey Cheng <beckysocute@gmail.com>
  • Loading branch information
lindseysimple committed Jul 13, 2023
1 parent cb9784b commit 342f0e5
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
5 changes: 3 additions & 2 deletions internal/core/metadata/application/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"context"
goErrors "errors"
"fmt"
"time"

bootstrapContainer "github.com/edgexfoundry/go-mod-bootstrap/v3/bootstrap/container"
"github.com/edgexfoundry/go-mod-bootstrap/v3/di"
Expand All @@ -34,8 +35,8 @@ import (
"github.com/edgexfoundry/edgex-go/internal/pkg/utils"
)

// the suggested minimum duration string for auto event interval
const minAutoEventInterval = "1ms"
// the suggested minimum duration for auto event interval
const minAutoEventInterval = 1 * time.Millisecond

// The AddDevice function accepts the new device model from the controller function
// and then invokes AddDevice function of infrastructure layer to add new device
Expand Down
9 changes: 2 additions & 7 deletions internal/pkg/utils/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,13 @@ import (
)

// CheckMinInterval parses the ISO 8601 time duration string to Duration type
// and evaluates if the duration value is smaller than the suggested minimum duration string
func CheckMinInterval(value string, min string, lc logger.LoggingClient) bool {
// and evaluates if the duration value is smaller than the suggested minimum duration
func CheckMinInterval(value string, minDuration time.Duration, lc logger.LoggingClient) bool {
valueDuration, err := time.ParseDuration(value)
if err != nil {
lc.Errorf("failed to parse the interval duration string %s to a duration time value: %v", value, err)
return false
}
minDuration, err := time.ParseDuration(min)
if err != nil {
lc.Errorf("failed to parse the minimum duration string %s to a duration time value: %v", value, err)
return false
}

if valueDuration < minDuration {
// the duration value is smaller than the min
Expand Down
9 changes: 5 additions & 4 deletions internal/pkg/utils/time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package utils

import (
"testing"
"time"

"github.com/edgexfoundry/go-mod-core-contracts/v3/clients/logger"

Expand All @@ -19,12 +20,12 @@ func TestCheckMinInterval(t *testing.T) {
tests := []struct {
name string
interval string
min string
min time.Duration
result bool
}{
{"valid - interval is bigger than the minimum value", "1s", "10ms", true},
{"invalid - interval is smaller than the minimum value", "100us", "1ms", false},
{"invalid - parsing duration string failed", "INVALID", "1ms", false},
{"valid - interval is bigger than the minimum value", "1s", 10 * time.Millisecond, true},
{"invalid - interval is smaller than the minimum value", "100us", 1 * time.Millisecond, false},
{"invalid - parsing duration string failed", "INVALID", 1 * time.Millisecond, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
5 changes: 3 additions & 2 deletions internal/support/scheduler/application/interval.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package application
import (
"context"
"fmt"
"time"

"github.com/edgexfoundry/edgex-go/internal/pkg/correlation"
"github.com/edgexfoundry/edgex-go/internal/pkg/utils"
Expand All @@ -23,8 +24,8 @@ import (
"github.com/edgexfoundry/go-mod-core-contracts/v3/models"
)

// the suggested minimum duration string for scheduler interval
const minSchedulerInterval = "10ms"
// the suggested minimum duration for scheduler interval
const minSchedulerInterval = 10 * time.Millisecond

// The AddInterval function accepts the new Interval model from the controller function
// and then invokes AddInterval function of infrastructure layer to add new Interval
Expand Down

0 comments on commit 342f0e5

Please sign in to comment.