RegressionTests__PipeStreamTest.st
author Claus Gittinger <cg@exept.de>
Tue, 09 Jul 2019 18:53:03 +0200
changeset 2327 bf482d49aeaf
parent 2009 f99d1003cfd9
permissions -rw-r--r--
#QUALITY by exept class: RegressionTests::StringTests added: #test82c_expanding
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
2009
f99d1003cfd9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 1906
diff changeset
    18
    | makeReader makeWriter count threads ok finished 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:[
2009
f99d1003cfd9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 1906
diff changeset
    24
        threads := 20.
1110
a38d8f5208fd class: RegressionTests::PipeStreamTest
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1109
diff changeset
    25
    ].
2009
f99d1003cfd9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 1906
diff changeset
    26
f99d1003cfd9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 1906
diff changeset
    27
    finished := false.
1109
ad8866ade273 class: RegressionTests::PipeStreamTest
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1082
diff changeset
    28
    ok := true.
1289
e1b9697a5b5e class: RegressionTests::PipeStreamTest
Stefan Vogel <sv@exept.de>
parents: 1215
diff changeset
    29
    blocker := Semaphore new: 2 - threads.
e1b9697a5b5e class: RegressionTests::PipeStreamTest
Stefan Vogel <sv@exept.de>
parents: 1215
diff changeset
    30
1594
f3698cd71e1c #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1447
diff changeset
    31
    makeReader := [:stream |
2009
f99d1003cfd9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 1906
diff changeset
    32
            [
f99d1003cfd9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 1906
diff changeset
    33
                | c |
f99d1003cfd9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 1906
diff changeset
    34
                c := 0.
f99d1003cfd9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 1906
diff changeset
    35
                [ stream atEnd ] whileFalse:[
f99d1003cfd9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 1906
diff changeset
    36
                    stream next.
f99d1003cfd9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 1906
diff changeset
    37
                    c := c + 1.
f99d1003cfd9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 1906
diff changeset
    38
                ].
f99d1003cfd9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 1906
diff changeset
    39
                stream close.
f99d1003cfd9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 1906
diff changeset
    40
                ok := ok and:[ count == c ].
f99d1003cfd9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 1906
diff changeset
    41
                blocker signal.
f99d1003cfd9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 1906
diff changeset
    42
            ]
f99d1003cfd9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 1906
diff changeset
    43
        ].
1109
ad8866ade273 class: RegressionTests::PipeStreamTest
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1082
diff changeset
    44
1594
f3698cd71e1c #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1447
diff changeset
    45
    makeWriter := [:stream |
2009
f99d1003cfd9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 1906
diff changeset
    46
            [
f99d1003cfd9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 1906
diff changeset
    47
                [
f99d1003cfd9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 1906
diff changeset
    48
                    count timesRepeat:[stream nextPut: $P]
f99d1003cfd9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 1906
diff changeset
    49
                ] on: Error do:[
f99d1003cfd9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 1906
diff changeset
    50
                    ok := false
f99d1003cfd9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 1906
diff changeset
    51
                ].
f99d1003cfd9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 1906
diff changeset
    52
                stream close.
f99d1003cfd9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 1906
diff changeset
    53
            ]
f99d1003cfd9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 1906
diff changeset
    54
        ].
f99d1003cfd9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 1906
diff changeset
    55
f99d1003cfd9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 1906
diff changeset
    56
    [    
f99d1003cfd9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 1906
diff changeset
    57
        threads timesRepeat:[
f99d1003cfd9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 1906
diff changeset
    58
            |pipe rs ws|
1109
ad8866ade273 class: RegressionTests::PipeStreamTest
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1082
diff changeset
    59
2009
f99d1003cfd9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 1906
diff changeset
    60
            pipe := NonPositionableExternalStream makePipe.
f99d1003cfd9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 1906
diff changeset
    61
            rs := pipe at:1.
f99d1003cfd9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 1906
diff changeset
    62
            ws := pipe at:2.
1109
ad8866ade273 class: RegressionTests::PipeStreamTest
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1082
diff changeset
    63
2009
f99d1003cfd9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 1906
diff changeset
    64
            (makeReader value: rs) fork.
f99d1003cfd9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 1906
diff changeset
    65
            (makeWriter value: ws) fork.
f99d1003cfd9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 1906
diff changeset
    66
        ].
1109
ad8866ade273 class: RegressionTests::PipeStreamTest
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1082
diff changeset
    67
2009
f99d1003cfd9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 1906
diff changeset
    68
        blocker wait.
f99d1003cfd9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 1906
diff changeset
    69
        finished := true.
f99d1003cfd9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 1906
diff changeset
    70
    ] valueWithTimeout:3 minutes.
f99d1003cfd9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 1906
diff changeset
    71
    
f99d1003cfd9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 1906
diff changeset
    72
    self assert:(finished and:[ok]).
1109
ad8866ade273 class: RegressionTests::PipeStreamTest
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1082
diff changeset
    73
ad8866ade273 class: RegressionTests::PipeStreamTest
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1082
diff changeset
    74
    "Created: / 27-03-2014 / 16:21:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
2009
f99d1003cfd9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 1906
diff changeset
    75
    "Modified: / 17-09-2018 / 15:30:19 / Claus Gittinger"
1109
ad8866ade273 class: RegressionTests::PipeStreamTest
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1082
diff changeset
    76
!
ad8866ade273 class: RegressionTests::PipeStreamTest
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1082
diff changeset
    77
121
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    78
testReadCheckPipe4
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    79
    "readCheck a pipe.
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    80
     Do this and interrupt the reading thread heavily"
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    81
1906
a7f11abb9d19 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1905
diff changeset
    82
    | cmd s p count|
121
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
1906
a7f11abb9d19 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1905
diff changeset
    84
    OperatingSystem isMSWINDOWSlike ifTrue:[
a7f11abb9d19 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1905
diff changeset
    85
        cmd := 'waitfor /T 3 pause'.
a7f11abb9d19 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1905
diff changeset
    86
    ] ifFalse:[
a7f11abb9d19 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1905
diff changeset
    87
        cmd := 'sleep 3'.
a7f11abb9d19 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1905
diff changeset
    88
    ].
a7f11abb9d19 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1905
diff changeset
    89
a7f11abb9d19 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1905
diff changeset
    90
    s := PipeStream readingFrom:cmd.
121
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    91
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    92
    p := [
1906
a7f11abb9d19 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1905
diff changeset
    93
        s readWait.
a7f11abb9d19 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1905
diff changeset
    94
        '   --- testReadCheckPipe4: readWait finished' printCR.
121
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    95
    ] forkAt:7.
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    96
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    97
    count := 0.
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    98
    [p isDead] whileFalse:[
1906
a7f11abb9d19 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1905
diff changeset
    99
        Delay waitForMilliseconds:5.
a7f11abb9d19 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1905
diff changeset
   100
        p interruptWith:[count := count + 1].
121
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   101
    ].
1903
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
   102
    ('   --- testReadCheckPipe4: readWait interrupted <1p> times' expandMacrosWith:count) printCR.
121
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   103
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   104
    s close.
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   105
1903
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
   106
    "/ 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
   107
    self assert:(count >= (3 / (1/20))).
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
   108
121
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   109
    "
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   110
     self new testReadCheckPipe4
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   111
    "
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   112
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   113
    "Modified: / 12.8.1998 / 13:42:13 / cg"
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   114
!
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   115
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   116
testReadCheckPipe5
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   117
    "readCheck a pipe.
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   118
     Do this and interrupt the reading thread heavily"
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   119
1906
a7f11abb9d19 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1905
diff changeset
   120
    | s p count line cmd|
121
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   121
1906
a7f11abb9d19 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1905
diff changeset
   122
    OperatingSystem isMSWINDOWSlike ifTrue:[
a7f11abb9d19 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1905
diff changeset
   123
        cmd := 'waitfor /T 3 pause & echo hello'.
a7f11abb9d19 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1905
diff changeset
   124
    ] ifFalse:[
a7f11abb9d19 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1905
diff changeset
   125
        cmd := 'sleep 3; echo hello'.
a7f11abb9d19 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1905
diff changeset
   126
    ].
a7f11abb9d19 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1905
diff changeset
   127
    s := PipeStream readingFrom:cmd.
121
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   128
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   129
    p := [
1906
a7f11abb9d19 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1905
diff changeset
   130
        s readWait.
a7f11abb9d19 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1905
diff changeset
   131
        line := s nextLine.
a7f11abb9d19 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1905
diff changeset
   132
        '   --- testReadCheckPipe5: readWait finished' printCR.
121
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   133
    ] forkAt:7.
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   134
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   135
    count := 0.
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   136
    [p isDead] whileFalse:[
1906
a7f11abb9d19 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1905
diff changeset
   137
        Delay waitForMilliseconds:5.
a7f11abb9d19 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1905
diff changeset
   138
        p interruptWith:[count := count + 1].
121
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   139
    ].
1903
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
   140
    ('   --- testReadCheckPipe5: readWait interrupted <1p> times' expandMacrosWith:count) printCR.
121
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   141
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   142
    s close.
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   143
1903
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
   144
    self assert:(line = 'hello').
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
   145
    "/ 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
   146
    self assert:(count >= (3 / (1/20))).
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
   147
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
     self new testReadCheckPipe5
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   150
    "
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   151
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   152
    "Modified: / 12.8.1998 / 13:42:13 / cg"
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   153
!
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   154
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   155
testReadPipe6
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   156
    "read a pipe.
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   157
     Do this and interrupt the reading thread heavily"
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   158
1906
a7f11abb9d19 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1905
diff changeset
   159
    | s p count error line  cmd|
121
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   160
1215
6c8217e7f690 class: RegressionTests::PipeStreamTest
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1110
diff changeset
   161
    error := nil.
121
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   162
170
247b3696e4cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 121
diff changeset
   163
    "/ self createTestFile.
121
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   164
1906
a7f11abb9d19 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1905
diff changeset
   165
    OperatingSystem isMSWINDOWSlike ifTrue:[
a7f11abb9d19 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1905
diff changeset
   166
        cmd := 'waitfor /T 3 pause'.
a7f11abb9d19 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1905
diff changeset
   167
    ] ifFalse:[
a7f11abb9d19 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1905
diff changeset
   168
        cmd := 'sleep 3'.
a7f11abb9d19 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1905
diff changeset
   169
    ].
a7f11abb9d19 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1905
diff changeset
   170
a7f11abb9d19 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1905
diff changeset
   171
    s := PipeStream readingFrom:cmd.
121
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   172
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   173
    p := [
1906
a7f11abb9d19 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1905
diff changeset
   174
        [
a7f11abb9d19 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1905
diff changeset
   175
            line := s nextLine.
a7f11abb9d19 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1905
diff changeset
   176
            "/ line printCR.
a7f11abb9d19 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1905
diff changeset
   177
        ] on: Error do:[:ex|
a7f11abb9d19 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1905
diff changeset
   178
            error := ex.
a7f11abb9d19 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1905
diff changeset
   179
        ]
121
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   180
    ] forkAt:7.
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   181
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   182
    count := 0.
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   183
    [p isDead] whileFalse:[
1906
a7f11abb9d19 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1905
diff changeset
   184
        Delay waitForMilliseconds:5.
a7f11abb9d19 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1905
diff changeset
   185
        p interruptWith:[count := count + 1].
121
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   186
    ].
1903
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
   187
    ('   --- testReadPipe6: read interrupted <1p> times' expandMacrosWith:count) printCR.
121
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   188
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   189
    s close.
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   190
1903
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
   191
    self assert: error isNil.
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
   192
    self assert: line isEmptyOrNil.
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
   193
    "/ 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
   194
    self assert:(count >= (3 / (1/20))).
1215
6c8217e7f690 class: RegressionTests::PipeStreamTest
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1110
diff changeset
   195
121
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   196
    "
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   197
     self new testReadPipe6
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   198
    "
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   199
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   200
    "Modified: / 12.8.1998 / 13:42:13 / cg"
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   201
!
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   202
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   203
testReadPipe7
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   204
    "read a pipe.
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   205
     Do this and interrupt the reading thread heavily"
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   206
1906
a7f11abb9d19 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1905
diff changeset
   207
    |s p count error line  cmd|
121
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   208
1906
a7f11abb9d19 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1905
diff changeset
   209
    OperatingSystem isMSWINDOWSlike ifTrue:[
a7f11abb9d19 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1905
diff changeset
   210
        cmd := 'waitfor /T 3 pause & echo hello'.
a7f11abb9d19 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1905
diff changeset
   211
    ] ifFalse:[
a7f11abb9d19 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1905
diff changeset
   212
        cmd := 'sleep 3; echo hello'.
a7f11abb9d19 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1905
diff changeset
   213
    ].
a7f11abb9d19 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1905
diff changeset
   214
    s := PipeStream readingFrom:cmd.
121
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   215
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   216
    p := [
1906
a7f11abb9d19 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1905
diff changeset
   217
        [
a7f11abb9d19 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1905
diff changeset
   218
            line := s nextLine.
a7f11abb9d19 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1905
diff changeset
   219
            "/ line printCR.
a7f11abb9d19 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1905
diff changeset
   220
        ] on: Error do:[:ex|
a7f11abb9d19 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1905
diff changeset
   221
            error := ex.
a7f11abb9d19 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1905
diff changeset
   222
        ]
121
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   223
    ] forkAt:7.
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   224
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   225
    count := 0.
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   226
    [p isDead] whileFalse:[
1906
a7f11abb9d19 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1905
diff changeset
   227
        Delay waitForMilliseconds:5.
a7f11abb9d19 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1905
diff changeset
   228
        p interruptWith:[count := count + 1].
121
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   229
    ].
1905
e3f76f9e8e60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1903
diff changeset
   230
    ('   --- read interrupted <1p> times' expandMacrosWith:count) printCR.
121
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   231
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   232
    s close.
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   233
1903
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
   234
    self assert: error isNil.
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
   235
    self assert: line = 'hello'.
dcd4e2bf4c31 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1594
diff changeset
   236
    "/ 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
   237
    self assert:(count >= (3 / (1/20))).
1215
6c8217e7f690 class: RegressionTests::PipeStreamTest
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1110
diff changeset
   238
121
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   239
    "
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   240
     self test7
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   241
    "
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   242
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   243
    "Modified: / 12.8.1998 / 13:42:13 / cg"
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   244
! !
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   245
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   246
!PipeStreamTest class methodsFor:'documentation'!
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   247
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   248
version
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   249
    ^ '$Header$'
3e9313b9af20 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   250
! !
1906
a7f11abb9d19 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 1905
diff changeset
   251