mirror of
https://github.com/juanfont/headscale.git
synced 2025-06-05 01:20:21 +02:00
improve OIDC TTL expire test
Waiting a bit more than the TTL of the OIDC token seems to remove some flakiness of this test. This furthermore makes use of a go func safe buffer which should avoid race conditions.
This commit is contained in:
parent
0e86c29f49
commit
7d0ae9ec64
@ -170,10 +170,11 @@ func TestOIDCExpireNodesBasedOnTokenExpiry(t *testing.T) {
|
|||||||
t.Logf("%d successful pings out of %d (before expiry)", success, len(allClients)*len(allIps))
|
t.Logf("%d successful pings out of %d (before expiry)", success, len(allClients)*len(allIps))
|
||||||
|
|
||||||
// This is not great, but this sadly is a time dependent test, so the
|
// This is not great, but this sadly is a time dependent test, so the
|
||||||
// safe thing to do is wait out the whole TTL time before checking if
|
// safe thing to do is wait out the whole TTL time (and a bit more out
|
||||||
// the clients have logged out. The Wait function can't do it itself
|
// of safety reasons) before checking if the clients have logged out.
|
||||||
// as it has an upper bound of 1 min.
|
// The Wait function can't do it itself as it has an upper bound of 1
|
||||||
time.Sleep(shortAccessTTL)
|
// min.
|
||||||
|
time.Sleep(shortAccessTTL + 10*time.Second)
|
||||||
|
|
||||||
assertTailscaleNodesLogout(t, allClients)
|
assertTailscaleNodesLogout(t, allClients)
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ory/dockertest/v3"
|
"github.com/ory/dockertest/v3"
|
||||||
@ -29,14 +30,36 @@ func ExecuteCommandTimeout(timeout time.Duration) ExecuteCommandOption {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// buffer is a goroutine safe bytes.buffer
|
||||||
|
type buffer struct {
|
||||||
|
store bytes.Buffer
|
||||||
|
mutex sync.Mutex
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write appends the contents of p to the buffer, growing the buffer as needed. It returns
|
||||||
|
// the number of bytes written.
|
||||||
|
func (b *buffer) Write(p []byte) (n int, err error) {
|
||||||
|
b.mutex.Lock()
|
||||||
|
defer b.mutex.Unlock()
|
||||||
|
return b.store.Write(p)
|
||||||
|
}
|
||||||
|
|
||||||
|
// String returns the contents of the unread portion of the buffer
|
||||||
|
// as a string.
|
||||||
|
func (b *buffer) String() string {
|
||||||
|
b.mutex.Lock()
|
||||||
|
defer b.mutex.Unlock()
|
||||||
|
return b.store.String()
|
||||||
|
}
|
||||||
|
|
||||||
func ExecuteCommand(
|
func ExecuteCommand(
|
||||||
resource *dockertest.Resource,
|
resource *dockertest.Resource,
|
||||||
cmd []string,
|
cmd []string,
|
||||||
env []string,
|
env []string,
|
||||||
options ...ExecuteCommandOption,
|
options ...ExecuteCommandOption,
|
||||||
) (string, string, error) {
|
) (string, string, error) {
|
||||||
var stdout bytes.Buffer
|
var stdout = buffer{}
|
||||||
var stderr bytes.Buffer
|
var stderr = buffer{}
|
||||||
|
|
||||||
execConfig := ExecuteCommandConfig{
|
execConfig := ExecuteCommandConfig{
|
||||||
timeout: dockerExecuteTimeout,
|
timeout: dockerExecuteTimeout,
|
||||||
|
Loading…
Reference in New Issue
Block a user