mirror of
https://github.com/mjl-/mox.git
synced 2025-07-12 17:44:35 +03:00
In tests, make initializing store/, its switchboard and an account more consistent.
Initialize store and switchboard first, then open account, and close in reverse order. Replace all "CheckClosed" calls with "WaitClosed", future changings will keep an account reference open for a bit after the last regular close, so we can't know that an account should be closed during tests. Remove one parameter from the (still too long) "start test server" function in imapserver testing code.
This commit is contained in:
@ -965,8 +965,8 @@ var InitialUIDValidity = func() uint32 {
|
||||
}
|
||||
|
||||
var openAccounts = struct {
|
||||
names map[string]*Account
|
||||
sync.Mutex
|
||||
names map[string]*Account
|
||||
}{
|
||||
names: map[string]*Account{},
|
||||
}
|
||||
@ -1029,6 +1029,7 @@ func OpenAccount(log mlog.Log, name string, checkLoginDisabled bool) (*Account,
|
||||
}
|
||||
|
||||
// openAccount opens an existing account, or creates it if it is missing.
|
||||
// Called with openAccounts lock held.
|
||||
func openAccount(log mlog.Log, name string) (a *Account, rerr error) {
|
||||
dir := filepath.Join(mox.DataDirPath("accounts"), name)
|
||||
return OpenAccountDB(log, dir, name)
|
||||
@ -1582,15 +1583,6 @@ func (a *Account) WaitClosed() {
|
||||
<-a.closed
|
||||
}
|
||||
|
||||
// CheckClosed asserts that the account has a zero reference count. For use in tests.
|
||||
func (a *Account) CheckClosed() {
|
||||
openAccounts.Lock()
|
||||
defer openAccounts.Unlock()
|
||||
if a.nused != 0 {
|
||||
panic(fmt.Sprintf("account still in use, %d refs", a.nused))
|
||||
}
|
||||
}
|
||||
|
||||
// Close reduces the reference count, and closes the database connection when
|
||||
// it was the last user.
|
||||
func (a *Account) Close() error {
|
||||
|
Reference in New Issue
Block a user