Files
vikunja/pkg/models/export_test.go
T
kolaente 044106508a fix: use caller's session in LoadFileMetaByID to prevent connection pool deadlock
Querying the global engine while the request already holds an open
transaction acquires a second pool connection. Under concurrent
attachment downloads (e.g. a kanban board full of image previews) all
pool connections end up held by transactions that each wait for an
extra connection that can never be freed, hanging every request until
restart.

The redundant meta load in the upload avatar provider is removed
entirely; the decoded image is all that path uses.
2026-08-16 17:57:52 +02:00

60 lines
1.9 KiB
Go

// Vikunja is a to-do list application to facilitate your life.
// Copyright 2018-present Vikunja and contributors. All rights reserved.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
package models
import (
"testing"
"code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/user"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestGetUserDataExportStatus(t *testing.T) {
t.Run("no export", func(t *testing.T) {
db.LoadAndAssertFixtures(t)
s := db.NewSession()
defer s.Close()
status, err := GetUserDataExportStatus(s, &user.User{ID: 15})
require.NoError(t, err)
assert.Nil(t, status)
})
t.Run("with export", func(t *testing.T) {
db.LoadAndAssertFixtures(t)
s := db.NewSession()
defer s.Close()
status, err := GetUserDataExportStatus(s, &user.User{ID: 1, ExportFileID: 1})
require.NoError(t, err)
require.NotNil(t, status)
assert.Equal(t, int64(1), status.ID)
})
t.Run("export points at a missing file", func(t *testing.T) {
db.LoadAndAssertFixtures(t)
// A dangling ExportFileID must read as "no export" rather than erroring,
// matching the download path which 404s the same case.
s := db.NewSession()
defer s.Close()
status, err := GetUserDataExportStatus(s, &user.User{ID: 15, ExportFileID: 9999})
require.NoError(t, err)
assert.Nil(t, status)
})
}