Skip to content

Commit e5ec679

Browse files
committed
8211325: test/jdk/java/net/Socket/LingerTest.java fails with cleaning up
Reviewed-by: shade Backport-of: 0cb267a
1 parent 7100a65 commit e5ec679

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

test/jdk/java/net/Socket/LingerTest.java

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -109,38 +109,45 @@ public static void main(String args[]) throws Exception {
109109
Socket s2 = ss.accept();
110110

111111
// setup conditions for untransmitted data and lengthy
112-
// linger interval
113-
s1.setSendBufferSize(128*1024);
112+
// linger interval
113+
s1.setSendBufferSize(128*1024);
114114
s1.setSoLinger(true, 30);
115115
s2.setReceiveBufferSize(1*1024);
116116

117117
// start sender
118-
Thread thr = new Thread(new Sender(s1));
119-
thr.start();
118+
Thread senderThread = new Thread(new Sender(s1));
119+
senderThread.start();
120120

121121
// other thread that will connect after 5 seconds.
122-
Other other = new Other(ss.getLocalPort(), 5000);
123-
thr = new Thread(other);
124-
thr.start();
122+
Other other = new Other(ss.getLocalPort(), 5000);
123+
Thread otherThread = new Thread(other);
124+
otherThread.start();
125125

126126
// give sender time to queue the data
127-
System.out.println ("Main sleep 1000");
128-
Thread.sleep(1000);
129-
System.out.println ("Main continue");
127+
System.out.println ("Main sleep 1000");
128+
Thread.sleep(1000);
129+
System.out.println ("Main continue");
130130

131131
// close the socket asynchronously
132-
(new Thread(new Closer(s1))).start();
132+
Thread closerThread = new Thread(new Closer(s1));
133+
closerThread.start();
133134

134-
System.out.println ("Main sleep 15000");
135+
System.out.println ("Main sleep 15000");
135136
// give other time to run
136-
Thread.sleep(15000);
137-
System.out.println ("Main closing serversocket");
137+
Thread.sleep(15000);
138+
System.out.println ("Main closing serversocket");
138139

139140
ss.close();
140141
// check that other is done
141-
if (!other.connected()) {
142+
if (!other.connected()) {
142143
throw new RuntimeException("Other thread is blocked");
143144
}
145+
146+
// await termination of all test related threads
147+
senderThread.join(60_000);
148+
otherThread.join(60_000);
149+
closerThread.join(60_000);
150+
144151
System.out.println ("Main ends");
145152
}
146153
}

0 commit comments

Comments
 (0)