PK
Size: a a a
PK
ЯК
PK
с
PK
AS
с
VY
VY
VY
VY
PK
// message - сообщение устройству.
type message struct {
feedback chan<- []byte // куда ответить
data []byte // само сообщение (c адресом и командой)
deadline time.Time // дедлайн отправки
}
//...
// Send - отправляет сообщение (по таймеру вызывается в цикле).
func Send(conn units.Caller) bool {
resp, err := conn.Call(me.msg.data)
timestamp := time.Now()
if err != nil {
me.attempts++
if me.attempts >= MsgDeliveryMaxAttempts || timestamp.After(me.msg.deadline) {
me.done(nil)
return true
}
return true
}
me.done(resp)
return true
}
//...
// done - возвращает ответ и чистит сообщение.
func done(data []byte) {
select {
case msg.feedback <- data:
default:
}
close(msg.feedback)
me.msg = nil
me.attempts = 0
me.sign = 0
}
DF
AD
AD
PK
func Test_Send(t *testing.T) {
conn := &echoConn{} // мок
// вкратце - возвращает тот канал message.feedback
repl, err := Put([]byte{1, 2, 3, 4})
if err != nil {
t.Errorf("Putting error: %s", err)
}
if !Send(conn) {
t.Error("Send could not shift")
}
select {
case <-repl:
default:
t.Error("No reply")
}
}
PK
DF
DF