Make TestValidAuthzExpires non-flaky. (#4778)
Previously, the test called `.Round(time.Minute)` on the expected and actual expiration times, intending to perform an "approximately equal" function. However, when the expected and actual times differed by a second, but they happened to fall on opposite sides of a rounding interval (i.e. 30 seconds into a minute), they would be rounded in opposite directions, resulting in a conclusion that they were not equal. This change instead defines an acceptable range of plus or minus a minute for the expiration time, and checks that the actual expiration time is in that interval.
This commit is contained in:
		
							parent
							
								
									36c1f1ab2d
								
							
						
					
					
						commit
						5254844ba2
					
				|  | @ -44,10 +44,12 @@ func TestValidAuthzExpires(t *testing.T) { | ||||||
| 	test.AssertEquals(t, authzOb.Status, "valid") | 	test.AssertEquals(t, authzOb.Status, "valid") | ||||||
| 	test.AssertEquals(t, authzOb.Identifier.Value, domains[0]) | 	test.AssertEquals(t, authzOb.Identifier.Value, domains[0]) | ||||||
| 
 | 
 | ||||||
| 	// The authz should have the expected expiry date
 | 	// The authz should have the expected expiry date, plus or minus a minute
 | ||||||
| 	expectedExpires := time.Now().AddDate(0, 0, validAuthorizationLifetime).Round(time.Minute) | 	expectedExpiresMin := time.Now().AddDate(0, 0, validAuthorizationLifetime).Add(-time.Minute) | ||||||
| 	actualExpires := authzOb.Expires.Round(time.Minute) | 	expectedExpiresMax := expectedExpiresMin.Add(2 * time.Minute) | ||||||
| 	if !expectedExpires.Equal(actualExpires) { | 	actualExpires := authzOb.Expires | ||||||
| 		t.Errorf("Wrong expiry. Got %q, expected %q", actualExpires, expectedExpires) | 	if actualExpires.Before(expectedExpiresMin) || actualExpires.After(expectedExpiresMax) { | ||||||
|  | 		t.Errorf("Wrong expiry. Got %s, expected it to be between %s and %s", | ||||||
|  | 			actualExpires, expectedExpiresMin, expectedExpiresMax) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue