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