Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

1.0 KB
Raw Blame
// SiYuan - https://github.com/siyuan-note/siyuan
// Copyright (c) 2020-present, b3log.org
// SPDX-License-Identifier: AGPL-3.0-or-later

package model

import (
	"testing"
	"time"

	"github.com/siyuan-note/siyuan/kernel/conf"
)

func TestCloudUserCachedDuringSync(t *testing.T) {
	previous := Conf
	Conf = NewAppConf()
	t.Cleanup(func() { Conf = previous })
	for _, user := range []*conf.User{nil, {UserId: "owner", UserTokenExpireTime: "0"}} {
		Conf.SetUser(user)
		Conf.UserData = "preserved-account"
		release := lockAssetSourceChange()
		done := make(chan struct{})
		var got *conf.User
		var err error
		go func() {
			got, err = GetCloudUser("ignored-token", true)
			close(done)
		}()
		select {
		case <-done:
			release()
		case <-time.After(3 * time.Second):
			release()
			<-done
			t.Fatal("cached account query waited for synchronization")
		}
		if err != nil || got != user || Conf.GetUser() != user || Conf.UserData != "preserved-account" {
			t.Fatal("cached query changed the account or attempted to refresh it")
		}
	}
}