terminals/tests/Xtreams__PipeReadingWritingTest.st
author mkobetic
Sun, 15 Jan 2012 22:27:17 +0000
changeset 43 b9a077d6ce14
parent 42 ad0f4782878a
child 52 a1363827b596
permissions -rw-r--r--
pipes

'From Smalltalk/X, Version:6.2.1 on 15-01-2012 at 05:26:29 PM'                  !

"{ 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$'
! !