Commit a045d7d3 authored by akwizgran's avatar akwizgran

Merge branch '1384-expiry-time' into 'master'

Fix off-by-one error in expiry calculation

Closes #1384

See merge request briar/briar!923
parents 37cd1cdd a29d5efd
Pipeline #2340 passed with stage
in 12 minutes and 53 seconds
......@@ -1882,7 +1882,7 @@ abstract class JdbcDatabase implements Database<Connection> {
+ " AND groupShared = TRUE AND messageShared = TRUE"
+ " AND deleted = FALSE"
+ " AND seen = FALSE AND requested = FALSE"
+ " AND (expiry < ? OR eta > ?)"
+ " AND (expiry <= ? OR eta > ?)"
+ " ORDER BY timestamp LIMIT ?";
ps = txn.prepareStatement(sql);
ps.setInt(1, c.getInt());
......@@ -1941,7 +1941,7 @@ abstract class JdbcDatabase implements Database<Connection> {
+ " AND groupShared = TRUE AND messageShared = TRUE"
+ " AND deleted = FALSE"
+ " AND seen = FALSE"
+ " AND (expiry < ? OR eta > ?)"
+ " AND (expiry <= ? OR eta > ?)"
+ " ORDER BY timestamp";
ps = txn.prepareStatement(sql);
ps.setInt(1, c.getInt());
......@@ -2072,7 +2072,7 @@ abstract class JdbcDatabase implements Database<Connection> {
+ " AND groupShared = TRUE AND messageShared = TRUE"
+ " AND deleted = FALSE"
+ " AND seen = FALSE AND requested = TRUE"
+ " AND (expiry < ? OR eta > ?)"
+ " AND (expiry <= ? OR eta > ?)"
+ " ORDER BY timestamp";
ps = txn.prepareStatement(sql);
ps.setInt(1, c.getInt());
......
......@@ -1818,8 +1818,8 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
@Test
public void testMessageRetransmission() throws Exception {
long now = System.currentTimeMillis();
long steps[] = {now, now, now + MAX_LATENCY * 2,
now + MAX_LATENCY * 2 + 1};
long steps[] = {now, now, now + MAX_LATENCY * 2 - 1,
now + MAX_LATENCY * 2};
Database<Connection> db =
open(false, new TestMessageFactory(), new ArrayClock(steps));
Connection txn = db.startTransaction();
......@@ -1845,12 +1845,12 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
// The message should expire after 2 * MAX_LATENCY
assertEquals(now + MAX_LATENCY * 2, db.getNextSendTime(txn, contactId));
// Time: now + MAX_LATENCY * 2
// Time: now + MAX_LATENCY * 2 - 1
// The message should not yet be sendable
ids = db.getMessagesToSend(txn, contactId, ONE_MEGABYTE, MAX_LATENCY);
assertTrue(ids.isEmpty());
// Time: now + MAX_LATENCY * 2 + 1
// Time: now + MAX_LATENCY * 2
// The message should have expired and should now be sendable
ids = db.getMessagesToSend(txn, contactId, ONE_MEGABYTE, MAX_LATENCY);
assertEquals(singletonList(messageId), ids);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment