Commit fece4705 authored by Sietse Ringers's avatar Sietse Ringers
Browse files

test: decrease runtime of keyshare wrong pin backoff test by making backoff variable

parent a63e88f7
......@@ -28,8 +28,11 @@ func (m *keysharePostgresUser) Data() *KeyshareUserData {
}
const MAX_PIN_TRIES = 3 // Number of tries allowed on pin before we start with exponential backoff
const BACKOFF_START = 30 // Initial ammount of time you are forced to back off when having multiple pin failures (in seconds)
const EMAIL_TOKEN_VALIDITY = 24 // Ammount of time your email validation token is valid (in hours)
const EMAIL_TOKEN_VALIDITY = 24 // Ammount of time user's email validation token is valid (in hours)
// Initial ammount of time user is forced to back off when having multiple pin failures (in seconds).
// var so that tests may change it.
var BACKOFF_START int64 = 30
func NewPostgresDatabase(connstring string) (KeyshareDB, error) {
db, err := sql.Open("pgx", connstring)
......
......@@ -53,6 +53,8 @@ func TestPostgresDBPinReservation(t *testing.T) {
SetupDatabase(t)
defer TeardownDatabase(t)
BACKOFF_START = 2
db, err := NewPostgresDatabase(postgresTestUrl)
require.NoError(t, err)
......@@ -62,7 +64,7 @@ func TestPostgresDBPinReservation(t *testing.T) {
ok, tries, wait, err := db.ReservePincheck(user)
require.NoError(t, err)
assert.True(t, ok)
assert.True(t, tries > 0)
assert.Equal(t, MAX_PIN_TRIES-1, tries)
assert.Equal(t, int64(0), wait)
for tries != 0 {
ok, tries, wait, err = db.ReservePincheck(user)
......@@ -70,7 +72,7 @@ func TestPostgresDBPinReservation(t *testing.T) {
assert.True(t, ok)
}
time.Sleep(time.Duration(wait-5) * time.Second)
time.Sleep(time.Duration(wait-1) * time.Second)
ok, tries, wait, err = db.ReservePincheck(user)
assert.NoError(t, err)
......@@ -78,7 +80,7 @@ func TestPostgresDBPinReservation(t *testing.T) {
assert.Equal(t, 0, tries)
assert.True(t, wait > 0)
time.Sleep(time.Duration(10 * time.Second))
time.Sleep(time.Duration(2 * time.Second))
ok, tries, wait, err = db.ReservePincheck(user)
assert.NoError(t, err)
......
Supports Markdown
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