RegressionTests__OperationInQueueTests.st
author Claus Gittinger <cg@exept.de>
Tue, 09 Jul 2019 18:53:03 +0200
changeset 2327 bf482d49aeaf
parent 2213 720d5d036a6d
permissions -rw-r--r--
#QUALITY by exept class: RegressionTests::StringTests added: #test82c_expanding

"{ Encoding: utf8 }"

"{ Package: 'stx:goodies/regression' }"

"{ NameSpace: RegressionTests }"

TestCase subclass:#OperationInQueueTests
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'tests-Regression-Processes'
!


!OperationInQueueTests methodsFor:'tests'!

test1
    |op opQ rslt|

    opQ := OperationQueue new.
    op := [ 1 + 2 ].

    ([
        rslt := opQ scheduleOperation:op.
        self assert:(rslt == 3)
    ] valueWithTimeout:20 seconds)
        isNil ifTrue:[
            self assert:false message:'test did not finish within 20 seconds'
        ].

    "Modified: / 29-03-2019 / 15:13:19 / Claus Gittinger"
!

test2
    |op opQ rslt|

    opQ := OperationQueue new.
    op := 1.

    ([
        rslt := opQ scheduleOperation:op.
        self assert:(rslt == 1)
    ] valueWithTimeout:10 seconds)
        isNil ifTrue:[
            self assert:false message:'test did not finish within 10 seconds'
        ].

    "Modified (format): / 03-07-2018 / 11:48:55 / Claus Gittinger"
!

test3
    |op opQ val1 val2 val3 val1b val2b val3b
     rslt rslt1 rslt2 rslt3 p0 p1 p2 p3 rslt1b rslt2b rslt3b p1b p2b p3b sz|

    ([ 
        opQ := OperationQueue new.
        opQ consumerProcessPriority:8.

        op := '1'.
        rslt := opQ scheduleOperation:op.

        self assert:(rslt = '1').

        self assert:(opQ size == 0).

        p0 := [
            opQ scheduleOperation:[ Delay waitForSeconds:1.].
        ] fork.

        p1 := [
            rslt1 := opQ scheduleOperation:[val1 := '1'].
        ] fork.

        p2 := [
            rslt2 := opQ scheduleOperation:[val2 := '2'].
        ] fork.

        p3 := [
            rslt3 := opQ scheduleOperation:[val3 := '3'].
        ] fork.

        Delay waitForSeconds:0.5.
        self assert:((sz := opQ size) == 3).

        p1b := [
            rslt1b := opQ scheduleOperation:[val1b := '1'].
        ] fork.

        p2b := [
            rslt2b := opQ scheduleOperation:[val2b := '2'].
        ] fork.

        p3b := [
            rslt3b := opQ scheduleOperation:[val3b := '3'].
        ] fork.

        Delay waitForSeconds:0.1.
        self assert:(opQ size == 6).

        Delay waitForSeconds:1.
        self assert:((sz := opQ size) == 0).

        self assert:(val1 == rslt1).
        self assert:(val2 == rslt2).
        self assert:(val3 == rslt3).
        self assert:(rslt1 = rslt1b).
        self assert:(rslt2 = rslt2b).
        self assert:(rslt3 = rslt3b).
        self assert:(val1b = rslt1b).
        self assert:(val2b = rslt2b).
        self assert:(val3b = rslt3b).
    ] valueWithTimeout:30 seconds)
        isNil ifTrue:[
            self assert:false message:'test did not finish within 30 seconds'
        ].

    "Modified: / 02-04-2019 / 15:34:28 / Claus Gittinger"
! !

!OperationInQueueTests class methodsFor:'documentation'!

version
    ^ '$Header$'
! !