Skip to content
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

fix: remove currentTimeMillis from code, tests are OK #1617

Merged
merged 1 commit into from Nov 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions pgjdbc/src/main/java/org/postgresql/Driver.java
Expand Up @@ -397,7 +397,7 @@ public void run() {
* @throws SQLException if a connection error occurs or the timeout is reached
*/
public Connection getResult(long timeout) throws SQLException {
long expiry = System.currentTimeMillis() + timeout;
long expiry = System.nanoTime() / 1000 + timeout;
synchronized (this) {
while (true) {
if (result != null) {
Expand All @@ -416,7 +416,7 @@ public Connection getResult(long timeout) throws SQLException {
}
}

long delay = expiry - System.currentTimeMillis();
long delay = expiry - System.nanoTime() / 1000;
if (delay <= 0) {
abandoned = true;
throw new PSQLException(GT.tr("Connection attempt timed out."),
Expand Down
Expand Up @@ -717,7 +717,7 @@ public synchronized void processNotifies(int timeoutMillis) throws SQLException
long startTime = 0;
int oldTimeout = 0;
if (useTimeout) {
startTime = System.currentTimeMillis();
startTime = System.nanoTime() / 1000;
try {
oldTimeout = pgStream.getSocket().getSoTimeout();
} catch (SocketException e) {
Expand Down Expand Up @@ -747,7 +747,7 @@ public synchronized void processNotifies(int timeoutMillis) throws SQLException
SQLWarning warning = receiveNoticeResponse();
addWarning(warning);
if (useTimeout) {
long newTimeMillis = System.currentTimeMillis();
long newTimeMillis = System.nanoTime() / 1000;
timeoutMillis += startTime - newTimeMillis; // Overflows after 49 days, ignore that
startTime = newTimeMillis;
if (timeoutMillis == 0) {
Expand Down
Expand Up @@ -5,8 +5,6 @@

package org.postgresql.hostchooser;

import static java.lang.System.currentTimeMillis;

import org.postgresql.util.HostSpec;

import java.util.ArrayList;
Expand All @@ -28,7 +26,7 @@ public class GlobalHostStatusTracker {
* @param hostStatus Latest known status for the host.
*/
public static void reportHostStatus(HostSpec hostSpec, HostStatus hostStatus) {
long now = currentTimeMillis();
long now = System.nanoTime() / 1000;
synchronized (hostStatusMap) {
HostSpecStatus hostSpecStatus = hostStatusMap.get(hostSpec);
if (hostSpecStatus == null) {
Expand All @@ -51,7 +49,7 @@ public static void reportHostStatus(HostSpec hostSpec, HostStatus hostStatus) {
static List<HostSpec> getCandidateHosts(HostSpec[] hostSpecs,
HostRequirement targetServerType, long hostRecheckMillis) {
List<HostSpec> candidates = new ArrayList<HostSpec>(hostSpecs.length);
long latestAllowedUpdate = currentTimeMillis() - hostRecheckMillis;
long latestAllowedUpdate = System.nanoTime() / 1000 - hostRecheckMillis;
synchronized (hostStatusMap) {
for (HostSpec hostSpec : hostSpecs) {
HostSpecStatus hostInfo = hostStatusMap.get(hostSpec);
Expand Down