summary refs log tree commit diff stats
path: root/tests/vm/tgorge.sh
blob: ba47afeae5e008a80e5b11d7eced9a7d06b5fab6 (plain) (blame)
1
2
#!/bin/sh
echo "gorge test"
22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
discard """
output: ""
"""
import threadpool, os

var chan: Channel[int]

chan.open(2)
chan.send(1)
chan.send(2)
doAssert(not chan.trySend(3)) # At this point chan is at max capacity

proc receiver() =
    doAssert(chan.recv() == 1)
    doAssert(chan.recv() == 2)
    doAssert(chan.recv() == 3)
    doAssert(chan.recv() == 4)
    doAssert(chan.recv() == 5)

var msgSent = false

proc emitter() =
    chan.send(3)
    msgSent = true

spawn emitter()
# At this point emitter should be stuck in `send`
sleep(100) # Sleep a bit to ensure that it is still stuck
doAssert(not msgSent)

spawn receiver()
sleep(100) # Sleep a bit to let receicer consume the messages
doAssert(msgSent) # Sender should be unblocked

doAssert(chan.trySend(4))
chan.send(5)
sync()