Skip to content

Commit c0cbfdb

Browse files
authored
Merge pull request #1759 from session-foundation/fix-regression-tests
fix: various fixes for regression tests to pass
2 parents c131fe5 + e39f616 commit c0cbfdb

File tree

5 files changed

+34
-19
lines changed

5 files changed

+34
-19
lines changed

ts/components/dialog/SessionCTA.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ export const useShowSessionCTACbWithVariant = () => {
417417
};
418418
};
419419

420-
export async function handleTriggeredProCTAs(dispatch: Dispatch<any>) {
420+
export async function handleTriggeredCTAs(dispatch: Dispatch<any>, fromAppStart: boolean) {
421421
const proAvailable = getFeatureFlag('proAvailable');
422422

423423
if (Storage.get(SettingsKey.proExpiringSoonCTA)) {
@@ -441,6 +441,10 @@ export async function handleTriggeredProCTAs(dispatch: Dispatch<any>) {
441441
);
442442
await Storage.put(SettingsKey.proExpiredCTA, false);
443443
} else {
444+
if (!fromAppStart) {
445+
// we only want to show the DonateCTA when the app starts, if needed
446+
return;
447+
}
444448
const dbCreationTimestampMs = await Data.getDBCreationTimestampMs();
445449
if (dbCreationTimestampMs && dbCreationTimestampMs + 7 * DURATION.DAYS < Date.now()) {
446450
const donateInteractions = getUrlInteractionsForUrl(APP_URL.DONATE);

ts/components/dialog/user-settings/pages/userSettingsHooks.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
type UserSettingsPage,
77
} from '../../../../state/ducks/modalDialog';
88
import { assertUnreachable } from '../../../../types/sqlSharedTypes';
9-
import { handleTriggeredProCTAs } from '../../SessionCTA';
9+
import { handleTriggeredCTAs } from '../../SessionCTA';
1010
import { getFeatureFlag } from '../../../../state/ducks/types/releasedFeaturesReduxTypes';
1111

1212
export function useUserSettingsTitle(page: UserSettingsModalState | undefined) {
@@ -82,7 +82,7 @@ export function useUserSettingsCloseAction(props: UserSettingsModalState) {
8282
return () => {
8383
dispatch(userSettingsModal(null));
8484
if (getFeatureFlag('proAvailable')) {
85-
void handleTriggeredProCTAs(dispatch);
85+
void handleTriggeredCTAs(dispatch, false);
8686
}
8787
props.afterCloseAction?.();
8888
};

ts/session/apis/snode_api/swarmPolling.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import {
5555
getCachedUserConfig,
5656
UserConfigWrapperActions,
5757
} from '../../../webworker/workers/browser/libsession/libsession_worker_userconfig_interface';
58+
import { isTestIntegration } from '../../../shared/env_vars';
5859

5960
const minMsgCountShouldRetry = 95;
6061
/**
@@ -969,6 +970,11 @@ export class SwarmPolling {
969970
window.log.info(
970971
`[onboarding] about to pollOnceForOurDisplayName of ${ed25519Str(pubkey.key)} from snode: ${ed25519Str(toPollFrom.pubkey_ed25519)} namespaces: ${[SnodeNamespaces.UserProfile]} `
971972
);
973+
if (isTestIntegration()) {
974+
// During integration tests, often deviceA might not have pushed to the swarm the userConfig that deviceB is looking for.
975+
// To deal with, this, we wait a bit here before trying to fetch the userConfig.
976+
await sleepFor(2000);
977+
}
972978
const retrieved = await SnodeAPIRetrieve.retrieveNextMessagesNoRetries(
973979
toPollFrom,
974980
pubkey.key,
@@ -983,13 +989,17 @@ export class SwarmPolling {
983989
`[onboarding] pollOnceForOurDisplayName of ${ed25519Str(pubkey.key)} from snode: ${ed25519Str(toPollFrom.pubkey_ed25519)} namespaces: ${[SnodeNamespaces.UserProfile]} returned: ${retrieved?.length}`
984990
);
985991
if (!retrieved?.length) {
992+
// Note: always print something so we know if the polling is hanging
993+
window.log.info(
994+
`[onboarding] pollOnceForOurDisplayName of ${ed25519Str(pubkey.key)} from snode: ${ed25519Str(toPollFrom.pubkey_ed25519)} namespaces: ${[SnodeNamespaces.UserProfile]} returned: ${retrieved?.length}`
995+
);
996+
986997
/**
987998
* Sometimes, a snode is out of sync with its swarm but still replies with what he thinks is the swarm's content.
988999
* When that happens, we can get a "no display name" error, as indeed, that snode didn't have a config message on user profile.
9891000
* To fix this, we've added a check over all of the snodes of our swarm, and we pick the first one that reports having a config message on user profile.
9901001
* This won't take care of the case where a snode has a message with an empty display name, but it's not the root issue that this was added for.
9911002
*/
992-
9931003
throw new Error(
9941004
`pollOnceForOurDisplayName of ${ed25519Str(pubkey.key)} from snode: ${ed25519Str(toPollFrom.pubkey_ed25519)} no results from user profile`
9951005
);

ts/state/ducks/conversations.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import { sectionActions } from './section';
3333
import { ed25519Str } from '../../session/utils/String';
3434
import { UserUtils } from '../../session/utils';
3535
import type { ProMessageFeature } from '../../models/proMessageFeature';
36-
import { handleTriggeredProCTAs } from '../../components/dialog/SessionCTA';
36+
import { handleTriggeredCTAs } from '../../components/dialog/SessionCTA';
3737
import { getFeatureFlag } from './types/releasedFeaturesReduxTypes';
3838

3939
export type MessageModelPropsWithoutConvoProps = {
@@ -1148,7 +1148,7 @@ export async function openConversationWithMessages(args: {
11481148

11491149
if (window.inboxStore) {
11501150
if (getFeatureFlag('proAvailable')) {
1151-
await handleTriggeredProCTAs(window.inboxStore.dispatch);
1151+
await handleTriggeredCTAs(window.inboxStore.dispatch, false);
11521152
}
11531153
}
11541154
}

ts/state/startup.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { initialNetworkDataState, networkDataActions } from './ducks/networkData
2929
import { initialProBackendDataState, proBackendDataActions } from './ducks/proBackendData';
3030
import { MessageQueue } from '../session/sending';
3131
import { AvatarMigrate } from '../session/utils/job_runners/jobs/AvatarMigrateJob';
32-
import { handleTriggeredProCTAs } from '../components/dialog/SessionCTA';
32+
import { handleTriggeredCTAs } from '../components/dialog/SessionCTA';
3333
import { UserSync } from '../session/utils/job_runners/jobs/UserSyncJob';
3434
import { forceSyncConfigurationNowIfNeeded } from '../session/utils/sync/syncUtils';
3535
import { SnodePool } from '../session/apis/snode_api/snodePool';
@@ -166,18 +166,19 @@ export const doAppStartUp = async () => {
166166
proBackendDataActions.refreshGetProDetailsFromProBackend({}) as any
167167
);
168168
if (window.inboxStore) {
169-
if (getDataFeatureFlag('useLocalDevNet') && isTestIntegration()) {
170-
/**
171-
* When running on the local dev net (during the regression tests), the network is too fast
172-
* and we show the DonateCTA before we got the time to grab the recovery phrase.
173-
* This sleepFor is there to give some time so we can grab the recovery phrase.
174-
* The regression test this is about is `Donate CTA, DB age >= 7 days`
175-
*/
176-
await sleepFor(1000);
177-
}
178-
if (window.inboxStore?.dispatch) {
179-
void handleTriggeredProCTAs(window.inboxStore.dispatch);
180-
}
169+
const delayedTimeout = getDataFeatureFlag('useLocalDevNet') && isTestIntegration() ? 2000 : 0;
170+
/**
171+
* When running on the local dev net (during the regression tests), the network is too fast
172+
* and we show the DonateCTA before we got the time to grab the recovery phrase.
173+
* This sleepFor is there to give some time so we can grab the recovery phrase.
174+
* The regression test this is about is `Donate CTA, DB age >= 7 days`
175+
*/
176+
// eslint-disable-next-line more/no-then
177+
void sleepFor(delayedTimeout).then(() => {
178+
if (window.inboxStore?.dispatch) {
179+
void handleTriggeredCTAs(window.inboxStore.dispatch, true);
180+
}
181+
});
181182
}
182183
// we want to (try) to fetch from the revocation server before we process
183184
// incoming messages, as some might have a pro proof that has been revoked

0 commit comments

Comments
 (0)