Fix failing tests and SQLITE_BUSY errors
This commit is contained in:
@@ -6,7 +6,9 @@ import (
|
||||
"fmt"
|
||||
"git.blackforestbytes.com/BlackForestBytes/goext/langext"
|
||||
"github.com/gin-gonic/gin"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestTokenKeys(t *testing.T) {
|
||||
@@ -722,3 +724,50 @@ func TestTokenKeysGetCurrent(t *testing.T) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestKeyTokenLastUsed(t *testing.T) {
|
||||
ws, baseUrl, stop := tt.StartSimpleWebserver(t)
|
||||
defer stop()
|
||||
|
||||
data := tt.InitSingleData(t, ws)
|
||||
|
||||
type keyobj struct {
|
||||
AllChannels bool `json:"all_channels"`
|
||||
Channels []string `json:"channels"`
|
||||
KeytokenId string `json:"keytoken_id"`
|
||||
MessagesSent int `json:"messages_sent"`
|
||||
Name string `json:"name"`
|
||||
OwnerUserId string `json:"owner_user_id"`
|
||||
Permissions string `json:"permissions"`
|
||||
TimestampLastUsed *string `json:"timestamp_lastused"`
|
||||
}
|
||||
|
||||
rkey1 := tt.RequestAuthGet[keyobj](t, data.ReadKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys/current", data.UID))
|
||||
readKeyID := rkey1.KeytokenId
|
||||
|
||||
time.Sleep(6 * time.Second) // wait for first DCI
|
||||
|
||||
rkey2 := tt.RequestAuthGet[keyobj](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys/%s", data.UID, readKeyID))
|
||||
|
||||
tt.AssertNotNil(t, "timestamp_lastused", rkey2.TimestampLastUsed)
|
||||
|
||||
rkey3 := tt.RequestAuthGet[keyobj](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys/%s", data.UID, readKeyID))
|
||||
|
||||
time.Sleep(6 * time.Second) // wait for first DCI
|
||||
|
||||
tt.AssertEqual(t, "timestamp_lastused", *rkey2.TimestampLastUsed, *rkey3.TimestampLastUsed) // should be unchanged, we did nothing with the readkey
|
||||
|
||||
tt.RequestAuthGetRaw(t, data.ReadKey, baseUrl, fmt.Sprintf("/api/v2/users/%s", data.UID))
|
||||
|
||||
rkey4 := tt.RequestAuthGet[keyobj](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys/%s", data.UID, readKeyID))
|
||||
|
||||
tt.AssertEqual(t, "timestamp_lastused", *rkey2.TimestampLastUsed, *rkey4.TimestampLastUsed) // still the same - the DCI is pending
|
||||
|
||||
time.Sleep(6 * time.Second) // wait for second DCI
|
||||
|
||||
rkey5 := tt.RequestAuthGet[keyobj](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys/%s", data.UID, readKeyID))
|
||||
|
||||
tt.AssertNotEqual(t, "timestamp_lastused", *rkey2.TimestampLastUsed, *rkey5.TimestampLastUsed) // did
|
||||
tt.AssertEqual(t, "timestamp_lastused", -1, strings.Compare(*rkey2.TimestampLastUsed, *rkey5.TimestampLastUsed))
|
||||
|
||||
}
|
||||
|
@@ -93,7 +93,7 @@ func StartSimpleWebserver(t *testing.T) (*logic.Application, string, func()) {
|
||||
AllowCors: &scn.Conf.Cors,
|
||||
GinDebug: &scn.Conf.GinDebug,
|
||||
BufferBody: langext.PTrue,
|
||||
Timeout: langext.Ptr(time.Duration(int64(scn.Conf.RequestTimeout) * int64(scn.Conf.RequestMaxRetry))),
|
||||
Timeout: langext.Ptr(time.Duration(int64(scn.Conf.RequestTimeout) * int64(scn.Conf.RequestMaxRetry+1))),
|
||||
BuildRequestBindError: logic.BuildGinRequestError,
|
||||
})
|
||||
|
||||
@@ -221,7 +221,7 @@ func CreateTestConfig(t *testing.T, dbfile1 string, dbfile2 string, dbfile3 stri
|
||||
conf.DBMain.ConnMaxIdleTime = 1 * time.Second
|
||||
conf.DBLogs.ConnMaxIdleTime = 1 * time.Second
|
||||
conf.DBRequests.ConnMaxIdleTime = 1 * time.Second
|
||||
conf.RequestMaxRetry = 32
|
||||
conf.RequestMaxRetry = 0 // 32 // normal server does retries - but should not _have_ to, so in out test we enfore no retrying...
|
||||
conf.RequestRetrySleep = 100 * time.Millisecond
|
||||
conf.ReturnRawErrors = true
|
||||
conf.DummyFirebase = true
|
||||
|
Reference in New Issue
Block a user