mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-10-29 17:52:24 -05:00
[chore] Test fixes (#788)
* use 'test' value for testrig storage backend * update test dependency * add WaitFor func in testrig * use WaitFor function instead of time.Sleep * tidy up tests * make SentMessages a sync.map * go fmt
This commit is contained in:
parent
bee8458a2d
commit
0245c606d7
30 changed files with 501 additions and 222 deletions
|
|
@ -87,3 +87,28 @@ func TimeMustParse(timeString string) time.Time {
|
|||
}
|
||||
return t
|
||||
}
|
||||
|
||||
// WaitFor calls condition every 200ms, returning true
|
||||
// when condition() returns true, or false after 5s.
|
||||
//
|
||||
// It's useful for when you're waiting for something to
|
||||
// happen, but you don't know exactly how long it will take,
|
||||
// and you want to fail if the thing doesn't happen within 5s.
|
||||
func WaitFor(condition func() bool) bool {
|
||||
tick := time.NewTicker(200 * time.Millisecond)
|
||||
defer tick.Stop()
|
||||
|
||||
timeout := time.NewTimer(5 * time.Second)
|
||||
defer timeout.Stop()
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-tick.C:
|
||||
if condition() {
|
||||
return true
|
||||
}
|
||||
case <-timeout.C:
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue