From f9f2c60719ab22ae6cd3db9018d3ededb549bda0 Mon Sep 17 00:00:00 2001 From: silver-it Date: Fri, 19 Jul 2024 15:29:05 +0800 Subject: [PATCH 01/10] chore: added a small update and Cypress try --- test/cypress/integration/group-chat.spec.js | 25 +++++++++++---------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/test/cypress/integration/group-chat.spec.js b/test/cypress/integration/group-chat.spec.js index 8215eb65e..101da36f5 100644 --- a/test/cypress/integration/group-chat.spec.js +++ b/test/cypress/integration/group-chat.spec.js @@ -51,26 +51,27 @@ describe('Group Chat Basic Features (Create & Join & Leave & Close)', () => { // considering it sync the chatroom contract from the beginning } else { const message = selfLeave ? `Left ${channelName}` : `Kicked a member from ${channelName}: ${leaver}` + const messageSelectors = { + last: 'div.c-message:last-child', + secondLast: 'div.c-message:nth-last-child(2)' + } + const assertKickerAndMessageContent = (msgSelector) => { + cy.get(`${msgSelector} .c-who > span:first-child`).should('contain', kicker) + cy.get(`${msgSelector} .c-notification`).should('contain', message) + } - let isLastElement = true if (byProposal) { // NOTE: when the member is kicked from the from by proposal // two messages will be created in general chatroom; INTERACTIVE, and NOTIFICATION // INTERACTIVE message should be created before the NOTIFICATION message // but sometimes (only in Cypress) NOTIFICATION message could be created earlier - // this block is to handle that heisenbug - cy.wait(1000) // eslint-disable-line cypress/no-unnecessary-waiting - cy.get('div.c-message:last-child').invoke('attr', 'class').then(classNames => { - isLastElement = classNames.includes('is-type-notification') + // below block is to handle that heisenbug. + cy.get(messageSelectors.last).invoke('attr', 'class').then(classNames => { + const isLastMsgTypeNotification = classNames.includes('is-type-notification') + assertKickerAndMessageContent(isLastMsgTypeNotification ? messageSelectors.last : messageSelectors.secondLast) }) - } - - if (isLastElement) { - cy.get('div.c-message:last-child .c-who > span:first-child').should('contain', kicker) - cy.get('div.c-message:last-child .c-notification').should('contain', message) } else { - cy.get('div.c-message:nth-last-child(2) .c-who > span:first-child').should('contain', kicker) - cy.get('div.c-message:nth-last-child(2) .c-notification').should('contain', message) + assertKickerAndMessageContent(messageSelectors.last) } } } From 4991725e67b6599b8b5c6bf061a87be933ee81dd Mon Sep 17 00:00:00 2001 From: silver-it Date: Fri, 19 Jul 2024 15:41:33 +0800 Subject: [PATCH 02/10] chore: added comment and Cypress retry --- test/cypress/integration/group-chat.spec.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/cypress/integration/group-chat.spec.js b/test/cypress/integration/group-chat.spec.js index 101da36f5..fd478c44e 100644 --- a/test/cypress/integration/group-chat.spec.js +++ b/test/cypress/integration/group-chat.spec.js @@ -65,6 +65,7 @@ describe('Group Chat Basic Features (Create & Join & Leave & Close)', () => { // two messages will be created in general chatroom; INTERACTIVE, and NOTIFICATION // INTERACTIVE message should be created before the NOTIFICATION message // but sometimes (only in Cypress) NOTIFICATION message could be created earlier + // and the order of two messages could be changed and it can cause the heisenbug // below block is to handle that heisenbug. cy.get(messageSelectors.last).invoke('attr', 'class').then(classNames => { const isLastMsgTypeNotification = classNames.includes('is-type-notification') From 4eacdaf23bdbe938ca7a721724dd1234fedaf839 Mon Sep 17 00:00:00 2001 From: silver-it Date: Fri, 19 Jul 2024 15:55:15 +0800 Subject: [PATCH 03/10] chore: check if group-chat passes three times in a row --- test/cypress/integration/group-chat.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/cypress/integration/group-chat.spec.js b/test/cypress/integration/group-chat.spec.js index fd478c44e..05f1325b4 100644 --- a/test/cypress/integration/group-chat.spec.js +++ b/test/cypress/integration/group-chat.spec.js @@ -66,7 +66,7 @@ describe('Group Chat Basic Features (Create & Join & Leave & Close)', () => { // INTERACTIVE message should be created before the NOTIFICATION message // but sometimes (only in Cypress) NOTIFICATION message could be created earlier // and the order of two messages could be changed and it can cause the heisenbug - // below block is to handle that heisenbug. + // below block is to handle that heisenbug cy.get(messageSelectors.last).invoke('attr', 'class').then(classNames => { const isLastMsgTypeNotification = classNames.includes('is-type-notification') assertKickerAndMessageContent(isLastMsgTypeNotification ? messageSelectors.last : messageSelectors.secondLast) From fec63dd07cdeae07e84d27da0b263d528682bc20 Mon Sep 17 00:00:00 2001 From: silver-it Date: Fri, 19 Jul 2024 16:11:01 +0800 Subject: [PATCH 04/10] chore: group-chat passes 4 times in a row --- test/cypress/integration/group-chat.spec.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/cypress/integration/group-chat.spec.js b/test/cypress/integration/group-chat.spec.js index 05f1325b4..63524c42e 100644 --- a/test/cypress/integration/group-chat.spec.js +++ b/test/cypress/integration/group-chat.spec.js @@ -69,7 +69,9 @@ describe('Group Chat Basic Features (Create & Join & Leave & Close)', () => { // below block is to handle that heisenbug cy.get(messageSelectors.last).invoke('attr', 'class').then(classNames => { const isLastMsgTypeNotification = classNames.includes('is-type-notification') - assertKickerAndMessageContent(isLastMsgTypeNotification ? messageSelectors.last : messageSelectors.secondLast) + assertKickerAndMessageContent( + isLastMsgTypeNotification ? messageSelectors.last : messageSelectors.secondLast + ) }) } else { assertKickerAndMessageContent(messageSelectors.last) From 5afb8588b760ae9e603f29ddd724eb3c7a40ac75 Mon Sep 17 00:00:00 2001 From: silver-it Date: Fri, 19 Jul 2024 16:18:04 +0800 Subject: [PATCH 05/10] chore: 5 times pass in a row means it fixes the heisenbug? maybe it's because assert inside then clause? --- test/cypress/integration/group-chat.spec.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/cypress/integration/group-chat.spec.js b/test/cypress/integration/group-chat.spec.js index 63524c42e..9e91fb9db 100644 --- a/test/cypress/integration/group-chat.spec.js +++ b/test/cypress/integration/group-chat.spec.js @@ -64,9 +64,9 @@ describe('Group Chat Basic Features (Create & Join & Leave & Close)', () => { // NOTE: when the member is kicked from the from by proposal // two messages will be created in general chatroom; INTERACTIVE, and NOTIFICATION // INTERACTIVE message should be created before the NOTIFICATION message - // but sometimes (only in Cypress) NOTIFICATION message could be created earlier - // and the order of two messages could be changed and it can cause the heisenbug - // below block is to handle that heisenbug + // but sometimes (mostly in Cypress) NOTIFICATION message could be created earlier + // and the order of two messages could be changed and it could cause the heisenbug. + // the below block is to handle that heisenbug cy.get(messageSelectors.last).invoke('attr', 'class').then(classNames => { const isLastMsgTypeNotification = classNames.includes('is-type-notification') assertKickerAndMessageContent( From 77df8ce4c50c20d53f43522ed798dac6de12038a Mon Sep 17 00:00:00 2001 From: silver-it Date: Tue, 23 Jul 2024 08:34:00 +0800 Subject: [PATCH 06/10] fix: added cy.wait and Cypress try --- test/cypress/integration/group-chat.spec.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/cypress/integration/group-chat.spec.js b/test/cypress/integration/group-chat.spec.js index 9e91fb9db..748dba87d 100644 --- a/test/cypress/integration/group-chat.spec.js +++ b/test/cypress/integration/group-chat.spec.js @@ -61,6 +61,7 @@ describe('Group Chat Basic Features (Create & Join & Leave & Close)', () => { } if (byProposal) { + cy.wait(2000) // eslint-disable-line cypress/no-unnecessary-waiting // NOTE: when the member is kicked from the from by proposal // two messages will be created in general chatroom; INTERACTIVE, and NOTIFICATION // INTERACTIVE message should be created before the NOTIFICATION message From 7b189d96b3007d20ae7ddd3d9426a910e100b312 Mon Sep 17 00:00:00 2001 From: silver-it Date: Tue, 23 Jul 2024 08:59:28 +0800 Subject: [PATCH 07/10] chore: added comment and Cypress retry --- frontend/controller/actions/group.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/frontend/controller/actions/group.js b/frontend/controller/actions/group.js index d6bbaba48..fc993a44a 100644 --- a/frontend/controller/actions/group.js +++ b/frontend/controller/actions/group.js @@ -971,6 +971,14 @@ export default (sbp('sbp/selectors/register', { const response = await sendMessage({ ...params, data: { ...data, passPayload } }) if (proposalToSend) { + // NOTE: sometimes 'notifyProposalStateInGeneralChatRoom' function could be called + // after the 'proposalVote' event is finished its processing (published, received, called process/sideEffect) + // it's not a big problem unless the proposal to remove someone from the group is accepted by the current vote. + // it's when the two messages will be created in general chatroom; one is to tells the proposal is approved + // and the other is to tell the member is left general chatroom. + // the order of two functions that will be called means the order of the two messages in general chatroom. + // so the order of messages isn't always same and that could cause the heisenbug below + // https://github.com/okTurtles/group-income/tree/2226-heisenbug-in-group-chatspecjs-more-persistent-one await sbp('gi.actions/group/notifyProposalStateInGeneralChatRoom', { groupID: contractID, proposal: proposalToSend From a1aa3ec39bdace2cd4fc99ed36f8eec6e5dd0890 Mon Sep 17 00:00:00 2001 From: silver-it Date: Tue, 23 Jul 2024 09:27:12 +0800 Subject: [PATCH 08/10] fix: removing cy.wait --- test/cypress/integration/group-chat.spec.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/cypress/integration/group-chat.spec.js b/test/cypress/integration/group-chat.spec.js index 748dba87d..d07346cca 100644 --- a/test/cypress/integration/group-chat.spec.js +++ b/test/cypress/integration/group-chat.spec.js @@ -61,7 +61,6 @@ describe('Group Chat Basic Features (Create & Join & Leave & Close)', () => { } if (byProposal) { - cy.wait(2000) // eslint-disable-line cypress/no-unnecessary-waiting // NOTE: when the member is kicked from the from by proposal // two messages will be created in general chatroom; INTERACTIVE, and NOTIFICATION // INTERACTIVE message should be created before the NOTIFICATION message @@ -416,6 +415,10 @@ describe('Group Chat Basic Features (Create & Join & Leave & Close)', () => { cy.getByDT('groupMembers').find('ul>li').should('have.length', 2) // user1 & user2 + // NOTE: this check is to wait until the 2 INTERACTIVE mesages are all created + // one for creating proposal and another is for proposal approval + cy.getByDT('groupChatLink').get('.c-badge.is-compact[aria-label="2 new notifications"]').contains('2') + cy.giRedirectToGroupChat() cy.giSwitchChannel(CHATROOM_GENERAL_NAME) From 65ae37c413fba14b9f2bfdba5eb67aa9bce5545b Mon Sep 17 00:00:00 2001 From: silver-it Date: Tue, 23 Jul 2024 09:37:59 +0800 Subject: [PATCH 09/10] chore: updated comment and check Cypress passed 2 times in a row --- test/cypress/integration/group-chat.spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/cypress/integration/group-chat.spec.js b/test/cypress/integration/group-chat.spec.js index d07346cca..aae8d443a 100644 --- a/test/cypress/integration/group-chat.spec.js +++ b/test/cypress/integration/group-chat.spec.js @@ -415,8 +415,8 @@ describe('Group Chat Basic Features (Create & Join & Leave & Close)', () => { cy.getByDT('groupMembers').find('ul>li').should('have.length', 2) // user1 & user2 - // NOTE: this check is to wait until the 2 INTERACTIVE mesages are all created - // one for creating proposal and another is for proposal approval + // NOTE: this check is to wait until 2 INTERACTIVE mesages are created + // one for creating proposal and another is for proposal approval. cy.getByDT('groupChatLink').get('.c-badge.is-compact[aria-label="2 new notifications"]').contains('2') cy.giRedirectToGroupChat() From cde5c763bd192f6a868dddb5a50c090b97667ea0 Mon Sep 17 00:00:00 2001 From: silver-it Date: Tue, 23 Jul 2024 09:46:59 +0800 Subject: [PATCH 10/10] chore: really passes 3 times in a row? --- test/cypress/integration/group-chat.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/cypress/integration/group-chat.spec.js b/test/cypress/integration/group-chat.spec.js index aae8d443a..246650d0c 100644 --- a/test/cypress/integration/group-chat.spec.js +++ b/test/cypress/integration/group-chat.spec.js @@ -416,7 +416,7 @@ describe('Group Chat Basic Features (Create & Join & Leave & Close)', () => { cy.getByDT('groupMembers').find('ul>li').should('have.length', 2) // user1 & user2 // NOTE: this check is to wait until 2 INTERACTIVE mesages are created - // one for creating proposal and another is for proposal approval. + // one for creating proposal and another is for proposal approval cy.getByDT('groupChatLink').get('.c-badge.is-compact[aria-label="2 new notifications"]').contains('2') cy.giRedirectToGroupChat()