terminals/tests/Xtreams__PipeReadingWritingTest.st
author mkobetic
Mon, 30 Jan 2012 22:29:41 +0000
changeset 71 b5baf23694f3
parent 58 e0530627f7b5
child 112 b6b3d8435bb7
permissions -rw-r--r--
(none)

"{ Package: 'stx:goodies/xtreams/terminals/tests' }"

"{ NameSpace: Xtreams }"

FiniteReadingWritingTests subclass:#PipeReadingWritingTest
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:'XtreamsPool'
	category:'Xtreams-Terminals-Tests'
!


!PipeReadingWritingTest methodsFor:'initialize-release'!

setUp
        | pipe |
        pipe := PipeStream makePipe.
        input := pipe first reading.
        output := pipe last writing.
!

tearDown
	input close.
	output close.
! !

!PipeReadingWritingTest methodsFor:'utilities'!

timeout: timeoutDuration server: serverBlock client: clientBlock
        "For tests that must be able to write and read at the same time, where they may block on each.
         Sockets, Pipes have an operating system buffer which dictates its bandwidth."

        |       timeout
                serverSuccess serverProcess serverLock
                clientSuccess clientProcess clientLock|

        timeout := false.
        serverLock := Semaphore new.
        clientLock := Semaphore new.
        serverSuccess := clientSuccess := false.
        serverProcess := [serverSuccess := serverBlock value. serverLock signal] fork.
        clientProcess := [clientSuccess := clientBlock value. clientLock signal] fork.

        serverLock wait.
        clientLock wait.

        self assert: serverSuccess.
        self assert: clientSuccess.
        self deny: timeout
! !

!PipeReadingWritingTest class methodsFor:'documentation'!

version_SVN
    ^ '$Id$'
! !