mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-07 05:32:43 +08:00
refactor: split driver cache
This commit is contained in:
@@ -1 +1 @@
|
||||
v5.0.0-beta-2505252353
|
||||
v5.0.0-beta-2505260035
|
||||
|
||||
37
uixt/cache.go
Normal file
37
uixt/cache.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package uixt
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
var driverCache sync.Map // key is serial, value is *XTDriver
|
||||
|
||||
// setupXTDriver initializes an XTDriver based on the platform and serial.
|
||||
func setupXTDriver(_ context.Context, args map[string]any) (*XTDriver, error) {
|
||||
platform, _ := args["platform"].(string)
|
||||
serial, _ := args["serial"].(string)
|
||||
if platform == "" {
|
||||
log.Warn().Msg("platform is not set, using android as default")
|
||||
platform = "android"
|
||||
}
|
||||
|
||||
// Check if driver exists in cache
|
||||
cacheKey := serial
|
||||
if cachedDriver, ok := driverCache.Load(cacheKey); ok {
|
||||
if driverExt, ok := cachedDriver.(*XTDriver); ok {
|
||||
log.Info().Str("platform", platform).Str("serial", serial).Msg("Using cached driver")
|
||||
return driverExt, nil
|
||||
}
|
||||
}
|
||||
|
||||
driverExt, err := NewDriverExt(platform, serial)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// store driver in cache
|
||||
driverCache.Store(cacheKey, driverExt)
|
||||
return driverExt, nil
|
||||
}
|
||||
1154
uixt/mcp_server.go
1154
uixt/mcp_server.go
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user