RegressionTests__OperationInQueueTests.st
author Stefan Vogel <sv@exept.de>
Mon, 30 Jul 2018 09:32:41 +0200
changeset 1995 bb6692faf0a6
parent 1983 c3cc934ecc69
child 2052 916a21ae08e1
permissions -rw-r--r--
#DOCUMENTATION by stefan class: RegressionTests::Helper class comment/format in: #isStcCompiledMethod:in: #isStcCompiledMethod:inClass:

"{ Encoding: utf8 }"

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

"{ NameSpace: RegressionTests }"

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


!OperationInQueueTests methodsFor:'tests'!

test1
    |op opQ rslt|

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

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

    "Modified (format): / 03-07-2018 / 11:48:52 / 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:3.].
        ] 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.5.
        self assert:(opQ size == 3).

        Delay waitForSeconds:3.
        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: / 03-07-2018 / 11:48:12 / Claus Gittinger"
! !

!OperationInQueueTests class methodsFor:'documentation'!

version
    ^ '$Header$'
! !