test: add test with changing address order

This commit is contained in:
James Houlahan
2020-05-06 09:57:34 +02:00
parent c61e8bdc71
commit 2d200f6f8c
19 changed files with 202 additions and 23 deletions

View File

@ -15,7 +15,7 @@
// You should have received a copy of the GNU General Public License
// along with ProtonMail Bridge. If not, see <https://www.gnu.org/licenses/>.
// Code generated by ./credits.sh at Fri Apr 24 08:21:38 CEST 2020. DO NOT EDIT.
// Code generated by ./credits.sh at Wed May 6 07:17:01 CEST 2020. DO NOT EDIT.
package bridge

View File

@ -34,6 +34,7 @@ const pollIntervalSpread = 5 * time.Second
type eventLoop struct {
cache *Cache
currentEventID string
currentEvent *pmapi.Event
pollCh chan chan struct{}
stopCh chan struct{}
notifyStopCh chan struct{}
@ -136,13 +137,18 @@ func (loop *eventLoop) start() { // nolint[funlen]
loop.log.WithField("lastEventID", loop.currentEventID).Warn("Subscription stopped")
}()
t := time.NewTicker(pollInterval - pollIntervalSpread)
defer t.Stop()
loop.hasInternet = true
go loop.pollNow()
loop.loop()
}
// loop is the main body of the event loop.
func (loop *eventLoop) loop() {
t := time.NewTicker(pollInterval - pollIntervalSpread)
defer t.Stop()
for {
var eventProcessedCh chan struct{}
select {
@ -251,6 +257,8 @@ func (loop *eventLoop) processNextEvent() (more bool, err error) { // nolint[fun
return false, errors.Wrap(err, "failed to get event")
}
loop.currentEvent = event
if event == nil {
return false, errors.New("received empty event")
}

View File

@ -46,6 +46,11 @@ func (store *Store) TestGetEventLoop() *eventLoop { //nolint[golint]
return store.eventLoop
}
// TestGetLastEvent returns last event processed by the store's event loop.
func (store *Store) TestGetLastEvent() *pmapi.Event { //nolint[golint]
return store.eventLoop.currentEvent
}
// TestGetStoreFilePath returns the filepath of the store's database file.
func (store *Store) TestGetStoreFilePath() string {
return store.filePath