truly fix streaming gap issue, remove sleeps from tests

This commit is contained in:
Nolan Lawson 2018-03-19 18:00:49 -07:00
parent eaa19f79e4
commit 00fd911579
4 changed files with 34 additions and 33 deletions

View file

@ -21,7 +21,8 @@ function processMessage (instanceName, timelineName, message) {
stop('processMessage')
}
export function createStream (streamingApi, instanceName, accessToken, timelineName) {
export function createStream (streamingApi, instanceName, accessToken,
timelineName, onOpenStream) {
return new TimelineStream(streamingApi, accessToken, timelineName, {
onMessage (msg) {
if (msg.event !== 'update' && msg.event !== 'delete' && msg.event !== 'notification') {
@ -33,6 +34,9 @@ export function createStream (streamingApi, instanceName, accessToken, timelineN
})
},
onOpen () {
if (onOpenStream) {
onOpenStream()
}
console.log('opened stream for timeline', timelineName)
},
onClose () {

View file

@ -43,12 +43,12 @@ export function timelineObservers (store) {
let accessToken = store.get('accessToken')
await updateInstanceInfo(currentInstance)
let checkInstanceAndTimelineAreUnchanged = () => (
let currentTimelineIsUnchanged = () => (
store.get('currentInstance') === currentInstance &&
store.get('currentTimeline') === currentTimeline
)
if (!checkInstanceAndTimelineAreUnchanged()) {
if (!currentTimelineIsUnchanged()) {
return
}
@ -56,23 +56,23 @@ export function timelineObservers (store) {
currentTimeline, 'timelineItemIds')
let firstTimelineItemId = timelineItemIds && timelineItemIds[0]
if (firstTimelineItemId) {
let onOpenStream = async () => {
if (!firstTimelineItemId || !currentTimelineIsUnchanged()) {
return
}
// fill in the "streaming gap" i.e. fetch the most recent 20 items so that there isn't
// a big gap in the timeline if you haven't looked at it in awhile
// TODO: race condition here, should start streaming while this request is ongoing
let newTimelineItems = await getTimeline(currentInstance, accessToken, currentTimeline,
null, firstTimelineItemId)
let newTimelineItems = await getTimeline(currentInstance, accessToken,
currentTimeline, null, firstTimelineItemId)
if (newTimelineItems.length) {
addStatusesOrNotifications(currentInstance, currentTimeline, newTimelineItems)
}
if (!checkInstanceAndTimelineAreUnchanged()) {
return
}
}
let instanceInfo = store.get('currentInstanceInfo')
currentTimelineStream = createStream(instanceInfo.urls.streaming_api,
currentInstance, accessToken, currentTimeline)
let streamingApi = instanceInfo.urls.streaming_api
currentTimelineStream = createStream(streamingApi, currentInstance, accessToken,
currentTimeline, onOpenStream)
if (process.env.NODE_ENV !== 'production') {
window.currentTimelineStream = currentTimelineStream

View file

@ -10,59 +10,56 @@ fixture`105-deletes.js`
.page`http://localhost:4002`
test('deleted statuses are removed from the timeline', async t => {
let timeout = 20000
await t.useRole(foobarRole)
.hover(getNthStatus(0))
let status = await postAs('admin', "I'm gonna delete this")
await sleep(1000)
await t.expect(getNthStatus(0).innerText).contains("I'm gonna delete this")
await t.expect(getNthStatus(0).innerText).contains("I'm gonna delete this", {timeout})
await deleteAs('admin', status.id)
await sleep(1000)
await t.expect(getNthStatus(0).innerText).notContains("I'm gonna delete this")
await t.expect(getNthStatus(0).innerText).notContains("I'm gonna delete this", {timeout})
await clickToNotificationsAndBackHome(t)
await t.expect(getNthStatus(0).innerText).notContains("I'm gonna delete this")
await t.expect(getNthStatus(0).innerText).notContains("I'm gonna delete this", {timeout})
await t.navigateTo('/notifications')
await forceOffline()
await t.click(homeNavButton)
await t.expect(getNthStatus(0).innerText).notContains("I'm gonna delete this")
await t.expect(getNthStatus(0).innerText).notContains("I'm gonna delete this", {timeout})
await forceOnline()
await t
.navigateTo('/')
.expect(getNthStatus(0).innerText).notContains("I'm gonna delete this")
.expect(getNthStatus(0).innerText).notContains("I'm gonna delete this", {timeout})
})
test('deleted statuses are removed from threads', async t => {
let timeout = 20000
await t.useRole(foobarRole)
.hover(getNthStatus(0))
let status = await postAs('admin', "I won't delete this")
let reply = await postReplyAs('admin', 'But I will delete this', status.id)
await sleep(5000)
await t.expect(getNthStatus(0).innerText).contains('But I will delete this')
.expect(getNthStatus(1).innerText).contains("I won't delete this")
await t.expect(getNthStatus(0).innerText).contains('But I will delete this', {timeout})
.expect(getNthStatus(1).innerText).contains("I won't delete this", {timeout})
.click(getNthStatus(1))
.expect(getUrl()).contains('/statuses')
.expect(getNthStatus(0).innerText).contains("I won't delete this")
.expect(getNthStatus(1).innerText).contains('But I will delete this')
.expect(getNthStatus(0).innerText).contains("I won't delete this", {timeout})
.expect(getNthStatus(1).innerText).contains('But I will delete this', {timeout})
await deleteAs('admin', reply.id)
await sleep(1000)
await t.expect(getNthStatus(1).exists).notOk()
.expect(getNthStatus(0).innerText).contains("I won't delete this")
.expect(getNthStatus(0).innerText).contains("I won't delete this", {timeout})
await t.navigateTo('/')
await forceOffline()
await t.click(getNthStatus(0))
.expect(getUrl()).contains('/statuses')
.expect(getNthStatus(1).exists).notOk()
.expect(getNthStatus(0).innerText).contains("I won't delete this")
.expect(getNthStatus(0).innerText).contains("I won't delete this", {timeout})
await forceOnline()
})
test('deleted statuses result in deleted notifications', async t => {
let timeout = 20000
await t.useRole(foobarRole)
.hover(getNthStatus(0))
.expect(notificationsNavButton.getAttribute('aria-label')).eql('Notifications')
let status = await postAs('admin', "@foobar yo yo foobar what's up")
await sleep(2000)
await t.expect(notificationsNavButton.getAttribute('aria-label')).eql('Notifications (1)')
await t.expect(notificationsNavButton.getAttribute('aria-label')).eql('Notifications (1)', {timeout})
await deleteAs('admin', status.id)
await sleep(5000)
await t.expect(notificationsNavButton.getAttribute('aria-label')).eql('Notifications')
await t.expect(notificationsNavButton.getAttribute('aria-label')).eql('Notifications', {timeout})
})

View file

@ -10,7 +10,7 @@ fixture`107-streaming-gap.js`
.page`http://localhost:4002`
test('fills in a status posted while away from timeline', async t => {
let timeout = 20000
let timeout = 30000
await t.useRole(foobarRole)
.click(localTimelineNavButton)
@ -23,7 +23,7 @@ test('fills in a status posted while away from timeline', async t => {
await t.expect(getNthStatus(0).innerText).contains('posted this while you were away!', {timeout})
.click(localTimelineNavButton)
.expect(getNthStatus(0).innerText).contains('posted this while you were away!', {timeout})
await sleep(2000)
.expect(getNthStatus(1).innerText).contains('heyo', {timeout})
await postAs('admin', 'posted this while you were watching')
await t.expect(getNthStatus(0).innerText).contains('posted this while you were watching', {timeout})
})