Reduce Android and iOS background work
This commit is contained in:
@@ -89,14 +89,24 @@ type Engine struct {
|
||||
func (e *Engine) Snapshot() Snapshot {
|
||||
e.mu.Lock()
|
||||
defer e.mu.Unlock()
|
||||
state := e.state
|
||||
if state == "" {
|
||||
state = "Stopped"
|
||||
return Snapshot{State: e.stateLocked(), Version: "1.14.3", RuntimeEvents: e.runtimeLogs.snapshot()}
|
||||
}
|
||||
|
||||
func (e *Engine) State() string {
|
||||
e.mu.Lock()
|
||||
defer e.mu.Unlock()
|
||||
return e.stateLocked()
|
||||
}
|
||||
|
||||
func (e *Engine) stateLocked() string {
|
||||
switch {
|
||||
case e.state == "":
|
||||
return "Stopped"
|
||||
case e.state == "Running" && e.ctx.Err() != nil:
|
||||
return "Failed"
|
||||
default:
|
||||
return e.state
|
||||
}
|
||||
if state == "Running" && e.ctx.Err() != nil {
|
||||
state = "Failed"
|
||||
}
|
||||
return Snapshot{State: state, Version: "1.14.3", RuntimeEvents: e.runtimeLogs.snapshot()}
|
||||
}
|
||||
|
||||
func (e *Engine) Start(parent context.Context, config Config) error {
|
||||
@@ -155,7 +165,11 @@ func (e *Engine) Start(parent context.Context, config Config) error {
|
||||
// Collect bounded, credential-redacted warning/error events in memory.
|
||||
// Raw upstream logs must never go to stderr or a user's log file.
|
||||
if !e.selfTestTrace {
|
||||
options.Log = &option.LogOptions{Level: "info", Output: os.DevNull}
|
||||
level := "info"
|
||||
if runtime.GOOS == "android" {
|
||||
level = "warn"
|
||||
}
|
||||
options.Log = &option.LogOptions{Level: level, Output: os.DevNull}
|
||||
}
|
||||
instance, err := box.New(box.Options{Options: options, Context: ctx})
|
||||
if err != nil {
|
||||
|
||||
@@ -91,6 +91,8 @@ func dispatch(id uint64, data []byte) (any, error) {
|
||||
if err := slot.engine.Stop(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
case "health":
|
||||
return map[string]string{"state": slot.engine.State()}, nil
|
||||
case "status":
|
||||
default:
|
||||
return nil, errors.New("unknown engine operation")
|
||||
|
||||
@@ -27,6 +27,13 @@ func TestABIRequestLifecycle(t *testing.T) {
|
||||
if _, err := dispatch(id, input); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
health, err := dispatch(id, []byte(`{"op":"health"}`))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if state, ok := health.(map[string]string); !ok || len(state) != 1 || state["state"] != "Running" {
|
||||
t.Fatalf("unexpected health payload: %#v", health)
|
||||
}
|
||||
if _, err := dispatch(id, input); err == nil {
|
||||
t.Fatal("duplicate start accepted")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user