Skip to content

Commit

Permalink
fix: Selenium Grid scaler logic on platformName is set empty or any
Browse files Browse the repository at this point in the history
Signed-off-by: Viet Nguyen Duc <[email protected]>
  • Loading branch information
VietND96 committed Jan 9, 2025
1 parent 3e87999 commit 48287b8
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions pkg/scalers/selenium_grid_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,35 +251,34 @@ func countMatchingSessions(sessions Sessions, browserName string, browserVersion
// This function checks if the request capabilities match the scaler metadata
func checkRequestCapabilitiesMatch(request Capability, browserName string, browserVersion string, _ string, platformName string) bool {
// Check if browserName matches
browserNameMatch := request.BrowserName == "" && browserName == "" ||
browserNameMatch := (request.BrowserName == "" && browserName == "") ||
strings.EqualFold(browserName, request.BrowserName)

// Check if browserVersion matches
browserVersionMatch := (request.BrowserVersion == "" && browserVersion == "") ||
(request.BrowserVersion == "stable" && browserVersion == "") ||
(strings.HasPrefix(browserVersion, request.BrowserVersion) && request.BrowserVersion != "" && browserVersion != "")
(request.BrowserVersion != "" && strings.HasPrefix(browserVersion, request.BrowserVersion))

// Check if platformName matches
platformNameMatch := request.PlatformName == "" && platformName == "" ||
strings.EqualFold(platformName, request.PlatformName)
platformNameMatch := (request.PlatformName == "" || strings.EqualFold("any", request.PlatformName) || strings.EqualFold(platformName, request.PlatformName)) &&
(platformName == "" || platformName == "any" || strings.EqualFold(platformName, request.PlatformName))

return browserNameMatch && browserVersionMatch && platformNameMatch
}

// This function checks if Node stereotypes or ongoing sessions match the scaler metadata
func checkStereotypeCapabilitiesMatch(capability Capability, browserName string, browserVersion string, sessionBrowserName string, platformName string) bool {
// Check if browserName matches
browserNameMatch := capability.BrowserName == "" && browserName == "" ||
browserNameMatch := (capability.BrowserName == "" && browserName == "") ||
strings.EqualFold(browserName, capability.BrowserName) ||
strings.EqualFold(sessionBrowserName, capability.BrowserName)

// Check if browserVersion matches
browserVersionMatch := capability.BrowserVersion == "" && browserVersion == "" ||
(strings.HasPrefix(browserVersion, capability.BrowserVersion) && capability.BrowserVersion != "" && browserVersion != "")
browserVersionMatch := (capability.BrowserVersion == "" && browserVersion == "") ||
(capability.BrowserVersion != "" && strings.HasPrefix(browserVersion, capability.BrowserVersion))

// Check if platformName matches
platformNameMatch := capability.PlatformName == "" && platformName == "" ||
strings.EqualFold(platformName, capability.PlatformName)
platformNameMatch := (capability.PlatformName == "" || strings.EqualFold("any", capability.PlatformName) || strings.EqualFold(platformName, capability.PlatformName)) &&
(platformName == "" || platformName == "any" || strings.EqualFold(platformName, capability.PlatformName))

return browserNameMatch && browserVersionMatch && platformNameMatch
}
Expand Down

0 comments on commit 48287b8

Please sign in to comment.