RegressionTests__PipeStreamTest.st
author Claus Gittinger <cg@exept.de>
Mon, 19 Mar 2018 14:50:42 +0100
changeset 1903 dcd4e2bf4c31
parent 1594 f3698cd71e1c
child 1905 e3f76f9e8e60
permissions -rw-r--r--
#QUALITY by cg class: RegressionTests::PipeStreamTest comment/format in: #testReadCheckPipe5 changed: #testReadCheckPipe4 #testReadPipe6 #testReadPipe7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1903
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
     1
"{ Encoding: utf8 }"
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
     2
1447
2351db93aa5b package changes
Claus Gittinger <cg@exept.de>
parents: 1289
diff changeset
     3
"{ Package: 'stx:goodies/regression' }"
121
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
"{ NameSpace: RegressionTests }"
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
TestCase subclass:#PipeStreamTest
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
	instanceVariableNames:''
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
	classVariableNames:''
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
	poolDictionaries:''
1082
a46d9682d459 category change
Claus Gittinger <cg@exept.de>
parents: 180
diff changeset
    11
	category:'tests-Regression-Streams'
121
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
!
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
!PipeStreamTest methodsFor:'tests'!
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
1109
ad8866ade273 class: RegressionTests::PipeStreamTest
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1082
diff changeset
    17
testPipeWriteRead
1594
f3698cd71e1c #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1447
diff changeset
    18
    | makeReader makeWriter count threads ok blocker|
1109
ad8866ade273 class: RegressionTests::PipeStreamTest
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1082
diff changeset
    19
ad8866ade273 class: RegressionTests::PipeStreamTest
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1082
diff changeset
    20
    count := 1000.
ad8866ade273 class: RegressionTests::PipeStreamTest
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1082
diff changeset
    21
    threads := 200.
1110
a38d8f5208fd class: RegressionTests::PipeStreamTest
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1109
diff changeset
    22
    "/ There's limit to 50 open files in BCC5.5 libc, sigh.
a38d8f5208fd class: RegressionTests::PipeStreamTest
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1109
diff changeset
    23
    OperatingSystem isMSWINDOWSlike ifTrue:[
1594
f3698cd71e1c #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1447
diff changeset
    24
        threads := 20.
1110
a38d8f5208fd class: RegressionTests::PipeStreamTest
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1109
diff changeset
    25
    ].
1109
ad8866ade273 class: RegressionTests::PipeStreamTest
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1082
diff changeset
    26
    ok := true.
1289
e1b9697a5b5e class: RegressionTests::PipeStreamTest
Stefan Vogel <sv@exept.de>
parents: 1215
diff changeset
    27
    blocker := Semaphore new: 2 - threads.
e1b9697a5b5e class: RegressionTests::PipeStreamTest
Stefan Vogel <sv@exept.de>
parents: 1215
diff changeset
    28
1594
f3698cd71e1c #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1447
diff changeset
    29
    makeReader := [:stream |
f3698cd71e1c #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1447
diff changeset
    30
            [
f3698cd71e1c #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1447
diff changeset
    31
                | c |
f3698cd71e1c #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1447
diff changeset
    32
                c := 0.
f3698cd71e1c #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1447
diff changeset
    33
                [ stream atEnd ] whileFalse:[
f3698cd71e1c #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1447
diff changeset
    34
                    stream next.
f3698cd71e1c #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1447
diff changeset
    35
                    c := c + 1.
f3698cd71e1c #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1447
diff changeset
    36
                ].
f3698cd71e1c #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1447
diff changeset
    37
                stream close.
f3698cd71e1c #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1447
diff changeset
    38
                ok := ok and:[ count == c ].
f3698cd71e1c #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1447
diff changeset
    39
                blocker signal.
f3698cd71e1c #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1447
diff changeset
    40
            ]
f3698cd71e1c #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1447
diff changeset
    41
        ].
1109
ad8866ade273 class: RegressionTests::PipeStreamTest
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1082
diff changeset
    42
1594
f3698cd71e1c #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1447
diff changeset
    43
    makeWriter := [:stream |
f3698cd71e1c #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1447
diff changeset
    44
            [
f3698cd71e1c #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1447
diff changeset
    45
                [ 
f3698cd71e1c #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1447
diff changeset
    46
                    count timesRepeat:[stream nextPut: $P] 
f3698cd71e1c #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1447
diff changeset
    47
                ] on: Error do:[
f3698cd71e1c #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1447
diff changeset
    48
                    ok := false
f3698cd71e1c #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1447
diff changeset
    49
                ].
f3698cd71e1c #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1447
diff changeset
    50
                stream close.
f3698cd71e1c #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1447
diff changeset
    51
            ]
f3698cd71e1c #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1447
diff changeset
    52
        ].
1109
ad8866ade273 class: RegressionTests::PipeStreamTest
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1082
diff changeset
    53
ad8866ade273 class: RegressionTests::PipeStreamTest
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1082
diff changeset
    54
    threads timesRepeat:[
1594
f3698cd71e1c #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1447
diff changeset
    55
        |pipe rs ws|
1109
ad8866ade273 class: RegressionTests::PipeStreamTest
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1082
diff changeset
    56
1594
f3698cd71e1c #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1447
diff changeset
    57
        pipe := NonPositionableExternalStream makePipe.
f3698cd71e1c #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1447
diff changeset
    58
        rs := pipe at:1.
f3698cd71e1c #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1447
diff changeset
    59
        ws := pipe at:2.
1109
ad8866ade273 class: RegressionTests::PipeStreamTest
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1082
diff changeset
    60
1594
f3698cd71e1c #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1447
diff changeset
    61
        (makeReader value: rs) fork.
f3698cd71e1c #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1447
diff changeset
    62
        (makeWriter value: ws) fork.
1109
ad8866ade273 class: RegressionTests::PipeStreamTest
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1082
diff changeset
    63
    ].
ad8866ade273 class: RegressionTests::PipeStreamTest
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1082
diff changeset
    64
ad8866ade273 class: RegressionTests::PipeStreamTest
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1082
diff changeset
    65
    blocker wait.
ad8866ade273 class: RegressionTests::PipeStreamTest
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1082
diff changeset
    66
    self assert: ok.
ad8866ade273 class: RegressionTests::PipeStreamTest
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1082
diff changeset
    67
ad8866ade273 class: RegressionTests::PipeStreamTest
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1082
diff changeset
    68
    "Created: / 27-03-2014 / 16:21:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
ad8866ade273 class: RegressionTests::PipeStreamTest
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1082
diff changeset
    69
!
ad8866ade273 class: RegressionTests::PipeStreamTest
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1082
diff changeset
    70
121
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
testReadCheckPipe4
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
    "readCheck a pipe.
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    73
     Do this and interrupt the reading thread heavily"
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    74
1903
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
    75
    | s p count|
121
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    76
1903
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
    77
    s := PipeStream readingFrom:'sleep 3'.
121
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    78
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    79
    p := [
1903
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
    80
        s readWait.
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
    81
        '   --- testReadCheckPipe4: readWait finished' printCR.
121
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
    ] forkAt:7.
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    84
    count := 0.
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    85
    [p isDead] whileFalse:[
1903
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
    86
        Delay waitForMilliseconds:5.
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
    87
        p interruptWith:[count := count + 1].
121
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
    ].
1903
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
    89
    ('   --- testReadCheckPipe4: readWait interrupted <1p> times' expandMacrosWith:count) printCR.
121
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    90
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    91
    s close.
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    92
1903
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
    93
    "/ assume that our timer resolution is at least 20Hz (usually it is much better...)
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
    94
    self assert:(count >= (3 / (1/20))).
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
    95
121
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    96
    "
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    97
     self new testReadCheckPipe4
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    98
    "
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    99
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   100
    "Modified: / 12.8.1998 / 13:42:13 / cg"
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   101
!
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   102
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   103
testReadCheckPipe5
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   104
    "readCheck a pipe.
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   105
     Do this and interrupt the reading thread heavily"
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   106
1903
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
   107
    | s p count line|
121
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   108
1903
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
   109
    s := PipeStream readingFrom:'sleep 3; echo hello'.
121
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   110
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   111
    p := [
1903
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
   112
        s readWait.
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
   113
        line := s nextLine.
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
   114
        '   --- testReadCheckPipe5: readWait finished' printCR.
121
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   115
    ] forkAt:7.
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   116
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   117
    count := 0.
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   118
    [p isDead] whileFalse:[
1903
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
   119
        Delay waitForMilliseconds:5.
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
   120
        p interruptWith:[count := count + 1].
121
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   121
    ].
1903
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
   122
    ('   --- testReadCheckPipe5: readWait interrupted <1p> times' expandMacrosWith:count) printCR.
121
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   123
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   124
    s close.
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   125
1903
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
   126
    self assert:(line = 'hello').
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
   127
    "/ assume that our timer resolution is at least 20Hz (usually it is much better...)
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
   128
    self assert:(count >= (3 / (1/20))).
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
   129
121
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   130
    "
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   131
     self new testReadCheckPipe5
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   132
    "
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   133
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   134
    "Modified: / 12.8.1998 / 13:42:13 / cg"
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   135
!
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   136
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   137
testReadPipe6
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   138
    "read a pipe.
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   139
     Do this and interrupt the reading thread heavily"
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   140
1903
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
   141
    | s p count error line |
121
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   142
1215
6c8217e7f690 class: RegressionTests::PipeStreamTest
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1110
diff changeset
   143
    error := nil.
121
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   144
170
247b3696e4cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 121
diff changeset
   145
    "/ self createTestFile.
121
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   146
1903
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
   147
    s := PipeStream readingFrom:'sleep 3'.
121
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   148
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   149
    p := [
1903
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
   150
        [
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
   151
            line := s nextLine printCR.
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
   152
        ] on: Error do:[:ex|
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
   153
            error := ex.
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
   154
        ]
121
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   155
    ] forkAt:7.
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   156
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   157
    count := 0.
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   158
    [p isDead] whileFalse:[
1903
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
   159
        Delay waitForMilliseconds:5.
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
   160
        p interruptWith:[count := count + 1].
121
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   161
    ].
1903
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
   162
    ('   --- testReadPipe6: read interrupted <1p> times' expandMacrosWith:count) printCR.
121
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   163
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   164
    s close.
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   165
1903
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
   166
    self assert: error isNil.
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
   167
    self assert: line isEmptyOrNil.
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
   168
    "/ assume that our timer resolution is at least 20Hz (usually it is much better...)
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
   169
    self assert:(count >= (3 / (1/20))).
1215
6c8217e7f690 class: RegressionTests::PipeStreamTest
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1110
diff changeset
   170
121
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   171
    "
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   172
     self new testReadPipe6
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   173
    "
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   174
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   175
    "Modified: / 12.8.1998 / 13:42:13 / cg"
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   176
!
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   177
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   178
testReadPipe7
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   179
    "read a pipe.
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   180
     Do this and interrupt the reading thread heavily"
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   181
1903
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
   182
    |s p count error line |
121
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   183
1903
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
   184
    s := PipeStream readingFrom:'sleep 3; echo hello'.
121
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   185
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   186
    p := [
1903
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
   187
        [
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
   188
            line := s nextLine printCR.
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
   189
        ] on: Error do:[:ex|
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
   190
            error := ex.
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
   191
        ]
121
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   192
    ] forkAt:7.
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   193
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   194
    count := 0.
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   195
    [p isDead] whileFalse:[
1903
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
   196
        Delay waitForMilliseconds:5.
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
   197
        p interruptWith:[count := count + 1].
121
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   198
    ].
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   199
    ('read interrupted <1p> times' expandMacrosWith:count) printCR.
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   200
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   201
    s close.
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   202
1903
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
   203
    self assert: error isNil.
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
   204
    self assert: line = 'hello'.
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
   205
    "/ assume that our timer resolution is at least 20Hz (usually it is much better...)
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
   206
    self assert:(count >= (3 / (1/20))).
1215
6c8217e7f690 class: RegressionTests::PipeStreamTest
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1110
diff changeset
   207
121
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   208
    "
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   209
     self test7
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   210
    "
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   211
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   212
    "Modified: / 12.8.1998 / 13:42:13 / cg"
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   213
! !
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   214
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   215
!PipeStreamTest class methodsFor:'documentation'!
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   216
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   217
version
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   218
    ^ '$Header$'
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   219
! !
1082
a46d9682d459 category change
Claus Gittinger <cg@exept.de>
parents: 180
diff changeset
   220