Prioritize Remote heartbeats across all reader operations
This commit is contained in:
1 parent
e724c503d0
commit
d7da6548e1
4 files changed
+72
-41
No files matched your search
@@ -184,3 +184,29 @@ func TestBrailleRequiresGrant(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestBrailleQueueCannotDelayDueHeartbeat(t *testing.T) {
|
||||
c, a, stream := inertSpeechStream(t, "controlled", []string{"braille-stream"})
|
||||
client := &fixtureClient{calls: make(chan readerCall, 4)}
|
||||
c.client = client
|
||||
ticks := make(chan time.Time, 1)
|
||||
ticks <- time.Now()
|
||||
stream.brailleOps <- sdk.RemoteBraille{Op: "size", Width: 20}
|
||||
client.hook = func(_ context.Context, method string, _, _ any) error {
|
||||
if method == "remote.braille" {
|
||||
a.cancel()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
done := make(chan struct{})
|
||||
go func() { defer close(done); c.speech_operations_ticks(a, stream, ticks) }()
|
||||
awaitDone(t, done)
|
||||
first := <-client.calls
|
||||
second := <-client.calls
|
||||
if first.method != "remote.heartbeat" || second.method != "remote.braille" {
|
||||
t.Fatalf("due heartbeat delayed: %s then %s", first.method, second.method)
|
||||
}
|
||||
if first.params.(sdk.RemoteOperation).Sequence != 1 || second.params.(sdk.RemoteBrailleRequest).Sequence != 2 {
|
||||
t.Fatal("operation order changed")
|
||||
}
|
||||
}
|
||||
+14
-17
@@ -208,6 +208,10 @@ func (c *coordinator) speech_release(stream *speechStream, bytes int) {
|
||||
func (c *coordinator) speech_operations(a *connectionAttempt, stream *speechStream) {
|
||||
ticker := time.NewTicker(time.Second)
|
||||
defer ticker.Stop()
|
||||
c.speech_operations_ticks(a, stream, ticker.C)
|
||||
}
|
||||
|
||||
func (c *coordinator) speech_operations_ticks(a *connectionAttempt, stream *speechStream, ticks <-chan time.Time) {
|
||||
var utterance uint64
|
||||
heartbeat := func() bool {
|
||||
if a.ctx.Err() != nil {
|
||||
@@ -223,10 +227,19 @@ func (c *coordinator) speech_operations(a *connectionAttempt, stream *speechStre
|
||||
return err == nil
|
||||
}
|
||||
for {
|
||||
// Every effect shares the heartbeat deadline, including Braille and
|
||||
// focus requests. A continuously ready queue must not starve it.
|
||||
select {
|
||||
case <-ticks:
|
||||
if !heartbeat() {
|
||||
return
|
||||
}
|
||||
default:
|
||||
}
|
||||
select {
|
||||
case <-a.ctx.Done():
|
||||
return
|
||||
case <-ticker.C:
|
||||
case <-ticks:
|
||||
if !heartbeat() {
|
||||
return
|
||||
}
|
||||
@@ -257,26 +270,10 @@ func (c *coordinator) speech_operations(a *connectionAttempt, stream *speechStre
|
||||
return
|
||||
}
|
||||
case key := <-stream.keys:
|
||||
select {
|
||||
case <-ticker.C:
|
||||
if !heartbeat() {
|
||||
c.key_release(stream)
|
||||
return
|
||||
}
|
||||
default:
|
||||
}
|
||||
if !c.deliver_key(a, stream, key) {
|
||||
return
|
||||
}
|
||||
case item := <-stream.incoming:
|
||||
select {
|
||||
case <-ticker.C:
|
||||
if !heartbeat() {
|
||||
c.speech_release(stream, item.bytes)
|
||||
return
|
||||
}
|
||||
default:
|
||||
}
|
||||
c.mu.Lock()
|
||||
ready := c.speech_ready_locked(a, stream)
|
||||
c.mu.Unlock()
|
||||
|
||||
Reference in new issue
Block a user