Skip to content

Fix wrong user signed in with e2e tests - Cypress cookie sharing - `can send message` test

Fix wrong user signed in with e2e tests (Cypress cookie sharing). Mainly you would notice the can send message test failing in CI and the screenshot shows the "Join room" button as if the fixtures didn't work.

Part of https://gitlab.com/gitlab-org/gitter/webapp/issues/2269

Found in https://gitlab.com/gitlab-org/gitter/webapp/merge_requests/1648

  • Added cy.visitAndEnsureUser(url, user); to make sure we start off the test correctly in the state we expect
    • I was finding that the test was using the user from a previous test even though cookies should be cleared between tests per Cypress defaults/docs
  • Fix up cookie sharing problem with a before hook hack people mentioned in https://github.com/cypress-io/cypress/issues/781#issuecomment-389508520

can send message

#chat-input-textarea isn't available because it thinks the user is roomMember: false (comes from the window.troupeContext).

I suspect there is some race condition on the backend even though we generate all the fixtures and room membership on the backend beforehand. Maybe some caching :/

It seems like we are suffering from https://github.com/cypress-io/cypress/issues/781

The problem is that the current test is using the user from the previous test. We login for each test but somehow the session/cookies/something is being shared across occasionally even though Cypress says they are cleared,

Cypress automatically clears all cookies before each new test starts by default

https://docs.cypress.io/api/cypress-api/cookies.html#Preserve-Once


You can tell this is happening if you add this to a test after the cy.visit(...)

cy.window()
  .its('troupeContext.user.id')
  .should('equal', fixtures.user1._id);

Here is a failing CI run after we added this check: https://gitlab.com/gitlab-org/gitter/webapp/-/jobs/354681264


Logs

It should be signing in as user1(id=5dd3adc97f6d2f4ecc5589fa) but it is instead using some user from the previous tests.

Server logs
2019-11-19T08:54:33.542Z - info: Fixture endpoint generated some new fixtures
{ user1:
   { __v: 0,
     displayName: 'Test 170 1574153622798',
     githubId: 1574153622969,
     githubToken: null,
     username: '_testuser_1721574153622798',
     staff: false,
     _id: '5dd3adc97f6d2f4ecc5589fa',
     _tv: 1,
     identities: '',
     emails: '',
     accessToken: '_test_bcb5e0e8_5700_4871_9133_53141b44e20d' },
  user2:
   { __v: 0,
     displayName: 'Test 173 1574153622798',
     githubId: 1574153622972,
     githubToken: null,
     username: '_testuser_1751574153622798',
     staff: false,
     _id: '5dd3adc97f6d2f4ecc5589fb',
     _tv: 1,
     identities: '',
     emails: '',
     accessToken: '_test_58eb420f_e095_480a_8554_a376278a8508' },
  group1:
   { __v: 0,
     name: '_group1-1801574153673528',
     uri: '_group1-1801574153673528',
     lcUri: '_group1-1801574153673528',
     avatarUrl: null,
     homeUri: '_group1-1801574153673528',
     lcHomeUri: '_group1-1801574153673528',
     _id: '5dd3adc97f6d2f4ecc558a02',
     avatarVersion: 0 },
  troupe1:
   { __v: 0,
     uri: '_test_1811574153622798',
     githubType: 'ORG',
     _id: '5dd3adc97f6d2f4ecc558a04',
     _tv: 1,
     providers: '',
     renamedLcUris: '',
     githubId: null,
     noindex: false,
     bans: '',
     userCount: 2,
     oneToOneUsers: '',
     oneToOne: false,
     status: 'ACTIVE',
     lcOwner: null,
     lcUri: '_test_1811574153622798',
     tags: '',
     topic: '' },
  troupeInGroup1:
   { __v: 0,
     uri: '_test_1821574153622798',
     groupId: '5dd3adc97f6d2f4ecc558a02',
     githubType: 'ORG',
     _id: '5dd3adc97f6d2f4ecc558a06',
     _tv: 1,
     providers: '',
     renamedLcUris: '',
     githubId: null,
     noindex: false,
     bans: '',
     userCount: 2,
     oneToOneUsers: '',
     oneToOne: false,
     status: 'ACTIVE',
     lcOwner: null,
     lcUri: '_test_1821574153622798',
     tags: '',
     topic: '' },
  message1:
   { __v: 0,
     fromUserId: '5dd3adc97f6d2f4ecc5589fa',
     toTroupeId: '5dd3adc97f6d2f4ecc558a04',
     text: 'hello from the parent',
     pub: false,
     _id: '5dd3adc97f6d2f4ecc558a08',
     _tv: 1,
     readBy: '',
     editedAt: null,
     sent: 'Tue Nov 19 2019 02:54:33 GMT-0600 (Central Standard Time)',
     issues: '',
     mentions: '',
     urls: '' },
  message2:
   { __v: 0,
     fromUserId: '5dd3adc97f6d2f4ecc5589fa',
     toTroupeId: '5dd3adc97f6d2f4ecc558a04',
     parentId: '5dd3adc97f6d2f4ecc558a08',
     text: 'hello from the child',
     pub: false,
     _id: '5dd3adc97f6d2f4ecc558a09',
     _tv: 1,
     readBy: '',
     editedAt: null,
     sent: 'Tue Nov 19 2019 02:54:33 GMT-0600 (Central Standard Time)',
     issues: '',
     mentions: '',
     urls: '' },
  userToBeTokenDeleted1:
   { __v: 0,
     displayName: 'Test 176 1574153622798',
     githubId: 1574153622975,
     githubToken: null,
     username: '_testuser_1781574153622798',
     staff: false,
     _id: '5dd3adc97f6d2f4ecc5589fc',
     _tv: 1,
     identities: '',
     emails: '',
     accessToken: '_test_6cc6a4ac_608a_4348_9f2e_efd384798605' },
  oAuthClientToBeDeleted1:
   { __v: 0,
     name: 'Test 179 1574153622798',
     clientKey: 'ecf72cf2a728ad6ac28de5168e83d765578b8390',
     clientSecret: 'e321da3093f94c87385da19decdbc23c07173ab5',
     revoked: false,
     ownerUserId: '5dd3adc97f6d2f4ecc5589fc',
     _id: '5dd3adc97f6d2f4ecc558a00' },
  oAuthAccessTokenToBeDeleted1:
   { __v: 0,
     token: '86588ca8566178e2104c35970ddbc4a12818cab8',
     userId: '5dd3adc97f6d2f4ecc5589fc',
     clientId: '5dd3adc97f6d2f4ecc558a00',
     _id: '5dd3adc97f6d2f4ecc558a01' } }
  gitter:app:room-context-service findRoomContext user=_testuser_1721574153622798(5dd3adc97f6d2f4ecc5589fa) uri=_test_1821574153622798 options=undefined +428ms
  gitter:app:uri-resolver uriResolver _test_1821574153622798 +2ms
  gitter:app:room-membership-service checkRoomMembership(troupeId=5dd3adc97f6d2f4ecc558a06 userId=5dd3adc97f6d2f4ecc5589fa) -> 1 ||| allUsersInRoom=5dd3adc97f6d2f4ecc5589fa,5dd3adc97f6d2f4ecc5589fb +8ms
  gitter:app:troupe-service findByIdLeanWithMembership found {"_id":"5dd3adc97f6d2f4ecc558a06","uri":"_test_1821574153622798","groupId":"5dd3adc97f6d2f4ecc558a02","githubType":"ORG","sd":{"type":null,"members":"PUBLIC","admins":"MANUAL","public":true,"_id":"5dd3adc97f6d2f4ecc558a07","extraAdmins":[],"extraMembers":[]},"_tv":1,"providers":[],"renamedLcUris":[],"githubId":null,"noindex":false,"bans":[],"userCount":2,"oneToOneUsers":[],"oneToOne":false,"status":"ACTIVE","lcOwner":null,"lcUri":"_test_1821574153622798","tags":[],"topic":"","__v":0,"id":"5dd3adc97f6d2f4ecc558a06"} roomMember=true +2ms
  gitter:app:uri-resolver _test_1821574153622798 resolved to {"user":null,"uri":"_test_1821574153622798","room":{"_id":"5dd3adc97f6d2f4ecc558a06","uri":"_test_1821574153622798","groupId":"5dd3adc97f6d2f4ecc558a02","githubType":"ORG","sd":{"type":null,"members":"PUBLIC","admins":"MANUAL","public":true,"_id":"5dd3adc97f6d2f4ecc558a07","extraAdmins":[],"extraMembers":[]},"_tv":1,"providers":[],"renamedLcUris":[],"githubId":null,"noindex":false,"bans":[],"userCount":2,"oneToOneUsers":[],"oneToOne":false,"status":"ACTIVE","lcOwner":null,"lcUri":"_test_1821574153622798","tags":[],"topic":"","__v":0,"id":"5dd3adc97f6d2f4ecc558a06"},"roomMember":true,"group":null} +2ms
  gitter:app:context-generator generateTroupeContext -> roomMember=true troupe=_test_1821574153622798(5dd3adc97f6d2f4ecc558a06) user=_testuser_1721574153622798(5dd3adc97f6d2f4ecc5589fa) +7ms
  gitter:app:room-membership-service checkRoomMembership(troupeId=5dd3adc97f6d2f4ecc558a06 userId=5dd3adc97f6d2f4ecc5589fa) -> 1 ||| allUsersInRoom=5dd3adc97f6d2f4ecc5589fa,5dd3adc97f6d2f4ecc5589fb +9ms
  gitter:app:room-membership-service findRoomIdsForUser(5dd3adc97f6d2f4ecc5589fa) +4ms
  gitter:app:context-generator generateTroupeContext -> roomMember=true troupe=_test_1821574153622798(5dd3adc97f6d2f4ecc558a06) user=_testuser_1721574153622798(5dd3adc97f6d2f4ecc5589fa) +1ms
  gitter:app:room-membership-service checkRoomMembership(troupeId=5dd3adc97f6d2f4ecc558a06 userId=5dd3adc97f6d2f4ecc5589fa) -> 1 ||| allUsersInRoom=5dd3adc97f6d2f4ecc5589fa,5dd3adc97f6d2f4ecc5589fb +10ms
2019-11-19T08:54:33.876Z - warn: eyeball: socket of175v7ka1cvbgrgs7c8r3idsvvdapj does not exist.
  gitter:app:room-context-service findRoomContext user=_testuser_1591574153622798(5dd3adc87f6d2f4ecc5589dd) uri=_test_1811574153622798 options=undefined +135ms
  gitter:app:uri-resolver uriResolver _test_1811574153622798 +2ms
  gitter:app:room-membership-service checkRoomMembership(troupeId=5dd3adc97f6d2f4ecc558a04 userId=5dd3adc87f6d2f4ecc5589dd) -> 0 ||| allUsersInRoom=5dd3adc97f6d2f4ecc5589fa,5dd3adc97f6d2f4ecc5589fb +12ms
  gitter:app:troupe-service findByIdLeanWithMembership found {"_id":"5dd3adc97f6d2f4ecc558a04","uri":"_test_1811574153622798","githubType":"ORG","sd":{"type":null,"members":"PUBLIC","admins":"MANUAL","public":true,"_id":"5dd3adc97f6d2f4ecc558a05","extraAdmins":["5dd3adc97f6d2f4ecc5589fa"],"extraMembers":[]},"_tv":1,"providers":[],"renamedLcUris":[],"githubId":null,"noindex":false,"bans":[],"userCount":2,"oneToOneUsers":[],"oneToOne":false,"status":"ACTIVE","lcOwner":null,"lcUri":"_test_1811574153622798","tags":[],"topic":"","__v":0,"id":"5dd3adc97f6d2f4ecc558a04"} roomMember=false +2ms
  gitter:app:uri-resolver _test_1811574153622798 resolved to {"user":null,"uri":"_test_1811574153622798","room":{"_id":"5dd3adc97f6d2f4ecc558a04","uri":"_test_1811574153622798","githubType":"ORG","sd":{"type":null,"members":"PUBLIC","admins":"MANUAL","public":true,"_id":"5dd3adc97f6d2f4ecc558a05","extraAdmins":["5dd3adc97f6d2f4ecc5589fa"],"extraMembers":[]},"_tv":1,"providers":[],"renamedLcUris":[],"githubId":null,"noindex":false,"bans":[],"userCount":2,"oneToOneUsers":[],"oneToOne":false,"status":"ACTIVE","lcOwner":null,"lcUri":"_test_1811574153622798","tags":[],"topic":"","__v":0,"id":"5dd3adc97f6d2f4ecc558a04"},"roomMember":false,"group":null} +2ms
  gitter:app:context-generator generateTroupeContext -> roomMember=false troupe=_test_1811574153622798(5dd3adc97f6d2f4ecc558a04) user=_testuser_1591574153622798(5dd3adc87f6d2f4ecc5589dd) +9ms
  gitter:app:room-membership-service checkRoomMembership(troupeId=5dd3adc97f6d2f4ecc558a04 userId=5dd3adc87f6d2f4ecc5589dd) -> 0 ||| allUsersInRoom=5dd3adc97f6d2f4ecc5589fa,5dd3adc97f6d2f4ecc5589fb +10ms
  gitter:app:room-membership-service findRoomIdsForUser(5dd3adc87f6d2f4ecc5589dd) +10ms
  gitter:app:context-generator generateTroupeContext -> roomMember=false troupe=_test_1811574153622798(5dd3adc97f6d2f4ecc558a04) user=_testuser_1591574153622798(5dd3adc87f6d2f4ecc5589dd) +1ms
  gitter:app:room-membership-service checkRoomMembership(troupeId=5dd3adc97f6d2f4ecc558a04 userId=5dd3adc87f6d2f4ecc5589dd) -> 0 ||| allUsersInRoom=5dd3adc97f6d2f4ecc5589fa,5dd3adc97f6d2f4ecc5589fb +11ms
  gitter:app:room-membership-service checkRoomMembership(troupeId=5dd3adc97f6d2f4ecc558a04 userId=5dd3adc87f6d2f4ecc5589dd) -> 0 ||| allUsersInRoom=5dd3adc97f6d2f4ecc5589fa,5dd3adc97f6d2f4ecc5589fb +354ms
  gitter:app:room-membership-service findRoomIdsForUser(5dd3adc87f6d2f4ecc5589dd) +317ms
Browser log
app:client-context window.troupeContext 
troupe:
associatedRepo: false
avatarUrl: "http://localhost:5000/api/private/avatars/gh/u/_test_1811574153622798"
backend: {type: null}
githubType: "ORG"
id: "5dd3adc97f6d2f4ecc558a04"
lurk: false
mentions: 0
meta: {}
name: "_test_1811574153622798"
noindex: false
oneToOne: false
permissions: {admin: false}
public: true
roomMember: false
security: "PUBLIC"
topic: ""
unreadItems: 0
uri: "_test_1811574153622798"
url: "/_test_1811574153622798"
userCount: 2
v: 1

user:
avatarUrl: "http://localhost:5000/api/private/avatars/g/u/_testuser_1591574153622798"
avatarUrlMedium: "/api/private/user-avatar/_testuser_1591574153622798?s=128"
avatarUrlSmall: "/api/private/user-avatar/_testuser_1591574153622798?s=60"
displayName: "Test 157 1574153622798"
id: "5dd3adc87f6d2f4ecc5589dd"
providers: ["github"]
staff: false
url: "/_testuser_1591574153622798"
username: "_testuser_1591574153622798"
v: 1


app:router-chat Rendering app with troupe +162ms {id: "5dd3adc97f6d2f4ecc558a04", name: "_test_1811574153622798", topic: "", avatarUrl: "http://localhost:5000/api/private/avatars/gh/u/_test_1811574153622798", uri: "_test_1811574153622798", …}
console.js:35 app:chat-toolbar-input Not a room member so showing join room button +51ms
console.js:35 app:client-context Troupe data contains no group: {"id":"5dd3adc97f6d2f4ecc558a04","name":"_test_1811574153622798","topic":"","avatarUrl":"http://localhost:5000/api/private/avatars/gh/u/_test_1811574153622798","uri":"_test_1811574153622798","oneToOne":false,"userCount":2,"unreadItems":0,"mentions":0,"lastAccessTime":"2019-11-19T08:54:34.258Z","lurk":false,"url":"/_test_1811574153622798","githubType":"ORG","associatedRepo":false,"security":"PUBLIC","noindex":false,"permissions":{"admin":false},"roomMember":false,"backend":{"type":null},"public":true,"meta":{},"v":1}
Edited by Eric Eastwood

Merge request reports