测试失败 - 测试编译时间太长。确保测试代码没有过多导入

问题描述 投票:0回答:1

我们的团队测试有时无法在 CI/CD (GitLab) 上运行,给出的提示之一是过度导入。是否有关于如何减少进口以避免此问题的建议,或有任何其他建议来阻止这种情况间歇性发生?

另外,为什么过度导入可能会影响浏览器连接?

这是错误:

ERROR Cannot establish one or more browser connections.
8 of 8 browser connections have not been established:
 - chrome:headless --no-sandbox --disable-dev-shm-usage
 - chrome:headless --no-sandbox --disable-dev-shm-usage
 - chrome:headless --no-sandbox --disable-dev-shm-usage
 - chrome:headless --no-sandbox --disable-dev-shm-usage
 - chrome:headless --no-sandbox --disable-dev-shm-usage
 - chrome:headless --no-sandbox --disable-dev-shm-usage
 - chrome:headless --no-sandbox --disable-dev-shm-usage
 - chrome:headless --no-sandbox --disable-dev-shm-usage
Hints:
 - Tests took too long to compile (2.03 min). Ensure the test code has no excessive imports.
 - The host machine may not be powerful enough to handle the specified concurrency factor (8). Decrease the concurrency factor or allocate more computing resources to the host machine.
 - Increase the Browser Initialization Timeout if its value is too low (currently: 2 minutes for local browsers and 6 minutes for remote browsers). The timeout determines how long TestCafe waits for browsers to be ready.
 - The error can also be caused by network issues or remote device failure. Make sure that your network connection is stable and you can reach the remote device.

以下是测试文件中的导入:

import {
  ANSWER_OBFUSCATION_TEST_ID,
  SOQnaTestIdsAnswerPreview,
} from 'chegg-web-app/libs/qna-so/constants/soqnaTestIds';
import {
  questionBody,
  selectByClassName,
  selectById,
  selectByTestId,
  thumbsUp,
} from '../helpers/locators';
import {
  answerTitleToolTip,
  bestAnswer,
  breadcrumbParentSubjectLink,
  breadcrumbQuestionLink,
  breadcrumbSubjectLink,
  breadcrumbSubjectQnALink,
  closeResubscribeModal,
  ctaBody,
  ctaButton,
  ctaHeader,
  ctaModal,
  expertAnswer,
  nextLink,
  nextLinkText,
  positiveRatingText,
  postAQuestionCard,
  previousLink,
  previousLinkText,
  soCtaButton,
  structuredAnswer,
  structuredAnswerPreview,
  transcribedImageText,
  transcriptionSkipLink,
  uaeAnswerPreviewHeader,
  uaeCloseCheckout,
  uaeFinalAnswerHeader,
} from '../helpers/locators/soqnaLocators';
import { AuthPage } from '../helpers/pages';
import soqna, { SOQNAPage } from '../helpers/pages/soqna';
import {
  LanguageRequestHook,
  a11y,
  getPagePath,
  getPageUrl,
  goBack,
  reloadPage,
  rioLogger,
  setStyleAttribute,
  userLogInWithCredentials,
  verifyRioEventv2,
} from '../helpers/shared';
import {
  accessSearchReturnedResult,
  answeredBy,
  expertVerified,
  getTheSolutionLink,
  getTotalCountSearchResults,
  greatMatchQuestionRenderer,
  navigateToSOQna,
  nonSubsAutomatedCTA,
  nonSubsCTA,
  verifyQuestionPreviewSERP,
} from '../helpers/soqnaHelpers';

const sharedHelpers = require('../helpers/shared');

import config from '../config';
import {
  askExpertClickEvent,
  bestAnswerTooltipEvent,
  mathSolverEvent,
  nextQuestionEvent,
  previousQuestionEvent,
  questionNavbarEvent,
  questionStatusEvent,
  questionViewEvent,
  seeAnswerClickEvent,
  showTranscribedClickEvent,
  sqnaStepsViewEvent,
  viewFullAnswerClickEvent,
  viewFullSolutionViewEvent,
} from '../helpers/soqnaRioEvents';

const { userVariables, ClientFunction } = require('testcafe');

import { CountryCode } from '@chegg/testcafe-for-chegg-com/helper/graphql/cartService/types';
import { SubscriptionType } from '@chegg/testcafe-for-chegg-com/helper/graphql/cdpService/types';
import {
  NonSubScriptionType,
  SubscriptionChange,
} from '@chegg/testcafe-for-chegg-com/helper/identity/types';
import { createUser } from '@chegg/testcafe-for-chegg-com/helper/identity/user';
import { createUserForCheckout2 } from '../helpers/commerce';
import {
  enterTextAndSubmit,
  enterTextAndSubmitFromChat,
} from '../helpers/qaauidEditorHelpers';

预先感谢您的任何建议。

testcafe
1个回答
0
投票

该错误同时指向浏览器初始化超时(2 分钟)和并发因素(同时 8 个浏览器)。尝试增加超时并减少并发系数,直到定期成功。如果它以不同方式失败,请从官方文档中查看其他常见问题,了解其他事情,您可以尝试优化以及如何执行此操作的提示。

导入需要时间来加载和解析,JavaScript 也需要进行 JIT(及时,“在运行文件之前”)编译。坏代码可能需要多次重新编译,因为它想“再试一次”来优化它。从无限循环到高延迟外部 API,存在太多潜在问题,这些问题可能在运行代码来初始化导入或运行它们时发生。最好的办法是使用调试来尝试找到瓶颈。

© www.soinside.com 2019 - 2024. All rights reserved.