Skip to content

8281511: java/net/ipv6tests/UdpTest.java fails with checkTime failed #3448

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions test/jdk/java/net/ipv6tests/TcpTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -37,6 +37,7 @@

import java.net.*;
import java.io.*;
import java.util.concurrent.TimeUnit;

public class TcpTest extends Tests {
static ServerSocket server, server1, server2;
Expand Down Expand Up @@ -194,13 +195,14 @@ static void test3 () throws Exception {
server = new ServerSocket (0);
server.setSoTimeout (5000);
int port = server.getLocalPort();
long t1 = System.currentTimeMillis();
long t1 = System.nanoTime();
try {
server.accept ();
throw new RuntimeException ("accept should not have returned");
} catch (SocketTimeoutException e) {}
t1 = System.currentTimeMillis() - t1;
checkTime (t1, 5000);
t1 = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - t1);
final long expectedTime = TimeUnit.SECONDS.toMillis(5);
checkIfTimeOut(TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - t1), expectedTime);

c1 = new Socket ();
c1.connect (new InetSocketAddress (ia4addr, port), 1000);
Expand Down
21 changes: 8 additions & 13 deletions test/jdk/java/net/ipv6tests/Tests.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -151,19 +151,14 @@ public static void comparePackets (DatagramPacket p1, DatagramPacket p2)
}
}

/* check the time got is within 50% of the time expected */
public static void checkTime (long got, long expected) {
checkTime(got, expected, expected);
}

/* check the time got is between start and end, given 50% tolerance */
public static void checkTime(long got, long start, long end) {
dprintln("checkTime: got = " + got + " start = " + start + " end = " + end);
long upper = end + (end / 2);
long lower = start - (start / 2);
if (got > upper || got < lower) {
throw new RuntimeException("checkTime failed: got " + got
+ ", expected between " + start + " and " + end);
/* check the timeout breached lower bound time rule */
public static void checkIfTimeOut(long got, long expected) {
dprintln("checkIfTimeOut: got = " + got + " lower bound = " + expected);

if (got < expected) {
throw new RuntimeException("checkIfTimeOut failed: got " + got
+ ", expected at least " + expected );
}
}

Expand Down
17 changes: 10 additions & 7 deletions test/jdk/java/net/ipv6tests/UdpTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -41,6 +41,7 @@
import java.net.InetAddress;
import java.net.PortUnreachableException;
import java.net.SocketTimeoutException;
import java.util.concurrent.TimeUnit;

public class UdpTest extends Tests {
static DatagramSocket c3, s1, s2, s3;
Expand Down Expand Up @@ -138,26 +139,27 @@ static void test2 () throws Exception {
s1 = new DatagramSocket ();
s2 = new DatagramSocket ();
s1.setSoTimeout (4000);
long t1 = System.currentTimeMillis();
long t1 = System.nanoTime();
try {
s1.receive (new DatagramPacket (new byte [128], 128));
throw new Exception ("expected receive timeout ");
} catch (SocketTimeoutException e) {
}
checkTime (System.currentTimeMillis() - t1, 4000);
final long expectedTime = TimeUnit.SECONDS.toMillis(4);
checkIfTimeOut(TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - t1), expectedTime);

/* check data can be exchanged now */

simpleDataExchange (s1, ia6addr, s2, ia4addr);

/* double check timeout still works */
t1 = System.currentTimeMillis();
t1 = System.nanoTime();
try {
s1.receive (new DatagramPacket (new byte [128], 128));
throw new Exception ("expected receive timeout ");
} catch (SocketTimeoutException e) {
}
checkTime (System.currentTimeMillis() - t1, 4000);
checkIfTimeOut(TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - t1), expectedTime);

/* check receive works after a delay < timeout */

Expand All @@ -174,9 +176,10 @@ public void run () {
} catch (Exception e) {}
}
});
t1 = System.currentTimeMillis();
t1 = System.nanoTime();
s1.receive (new DatagramPacket (new byte [128], 128));
checkTime (System.currentTimeMillis() - t1, 2000, 10000);
final long startTime = TimeUnit.SECONDS.toMillis(2);
checkIfTimeOut(TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - t1), startTime);
s1.close ();
s2.close ();
System.out.println ("Test2: OK");
Expand Down