fix: #83
This commit is contained in:
parent
6a7f9f058c
commit
9efc08cb2f
|
@ -106,7 +106,7 @@ proc pushTo*(s: BufferStream, data: seq[byte]) {.async.} =
|
||||||
try:
|
try:
|
||||||
await s.lock.acquire()
|
await s.lock.acquire()
|
||||||
var index = 0
|
var index = 0
|
||||||
while true:
|
while not s.closed():
|
||||||
while index < data.len and s.readBuf.len < s.maxSize:
|
while index < data.len and s.readBuf.len < s.maxSize:
|
||||||
s.readBuf.addLast(data[index])
|
s.readBuf.addLast(data[index])
|
||||||
inc(index)
|
inc(index)
|
||||||
|
|
|
@ -440,3 +440,23 @@ suite "BufferStream":
|
||||||
|
|
||||||
check:
|
check:
|
||||||
waitFor(pipeTest()) == true
|
waitFor(pipeTest()) == true
|
||||||
|
|
||||||
|
test "shouldn't get stuck on close":
|
||||||
|
proc test(): Future[bool] {.async.} =
|
||||||
|
proc createMessage(tmplate: string, size: int): seq[byte] =
|
||||||
|
result = newSeq[byte](size)
|
||||||
|
for i in 0 ..< len(result):
|
||||||
|
result[i] = byte(tmplate[i mod len(tmplate)])
|
||||||
|
|
||||||
|
var stream = newBufferStream()
|
||||||
|
var message = createMessage("MESSAGE", DefaultBufferSize * 2 + 1)
|
||||||
|
var fut = stream.pushTo(message)
|
||||||
|
await stream.close()
|
||||||
|
try:
|
||||||
|
await wait(fut, 100.milliseconds)
|
||||||
|
result = true
|
||||||
|
except AsyncTimeoutError:
|
||||||
|
result = false
|
||||||
|
|
||||||
|
check:
|
||||||
|
waitFor(test()) == true
|
Loading…
Reference in New Issue