迁移服务器后Cypress测试因内存不足崩溃,求内存调整方案
服务器迁移后Chrome运行Cypress测试内存崩溃问题解决方案
问题说明
服务器迁移至新机器后,使用Chrome浏览器执行Cypress测试时,频繁出现内存不足导致的崩溃问题。已尝试设置numTestsKeptInMemory: 0,但问题依旧。当前cypress.json中的测试文件配置如下:
"testFiles": [ "01_Settings/KeyMateOnline/settings.js", "GRP_1000_Groups and SiteCollections/TC_5.0_GRP_1002_CreateNewGroup.js", "GRP_1000_SGroups and SiteCollections/TC_5.0_GRP_1003_Creating a new SiteCollection.js", "SNP_0800_Snapshots/TC_5.0_SNP_0801_Manual Snapshot Creation.js", "REP_0500_Reporting Functions/REP_1_Permissions by User/TC_5.0_REP_1_0501_Filter by Role.js", "REP_0500_Reporting Functions/REP_1_Permissions by User/TC_5.0_REP_1_0502_Filter by Member.js", "REP_0500_Reporting Functions/REP_2_Permissions by Role/TC_5.0_REP_2_0504_Filter by Role.js", "REP_0500_Reporting Functions/REP_2_Role-based Permissions/TC_5.0_REP_2_0505_Filter by Member.js", "REP_0500_Reporting Functions/REP_3_Membership by Role/TC_5.0_REP_3_0506_Filter Membership by Role.js", "REP_0500_Reportovací funkce/REP_4_Sdílení/TC_5.0_REP_4_0509_Filtr Sdílení.js", "EXE_0600_Execution Function/EXE_1_Group Membership/TC_5.0_EXE_1_0600_Adding Selected User to SP Group.js", "SNP_0800_Snapshots/TC_5.0_SNP_0800_Smazání Snapshotu.js", "SNP_0800_Snapshots/TC_5.0_SNP_0801_Manually create Snapshot.js", "EXE_0600_Execution Functions/EXE_1_Group Membership/TC_5.0_EXE_1_0602_Removing selected user from SP group.js", "SNP_0800_Snapshots/TC_5.0_SNP_0800_Smazání Snapshotu.js", "SNP_0800_Snapshots/TC_5.0_SNP_0801_Manual creation of Snapshot.js", "EXE_0600_Execution Functions/EXE_2_Permissions/TC_5.0_EXE_2_0601_Assign permissions to specific selected users.js", "SNP_0800_Snapshots/TC_5.0_SNP_0800_Smazání Snapshotu.js", "SNP_0800_Snapshots/TC_5.0_SNP_0801_Manual creation of Snapshot.js", "EXE_0600_Execution Functions/EXE_2_Permissions/TC_5.0_EXE_2_0603_Removing permissions for specific selected users.js", "SNP_0800_Snapshots/TC_5.0_SNP_0803_Creating Exception from Snapshots.js", "SNP_0800_Snapshots/TC_5.1_SNP_0804_View and delete Snapshots exception.js", "NTF_1100_Notifications/TC_5.1_NTF_1100_Creating a new notification for a specific site.js", "NTF_1100_Notifications/TC_5.1_NTF_1101_Display Notification Overview.js", "MSP_1200_Multisnapshot/TC_5.1_MSP_1200_Creating a report in the main Site collection container.js", "GRP_1000_SGroups and SiteCollections/TC_5.0_GRP_1008/Delete Site Collection.js" ]
解决建议
给Chrome设置内存上限:在cypress.json中添加Chrome启动参数,手动分配内存。示例配置:
"env": { "CHROME_FLAGS": "--max-old-space-size=4096" }其中
4096代表4GB内存,可根据新机器的内存配置调整数值(单位为MB)。清理并拆分测试用例:从配置中可见存在重复的测试文件(比如多次出现的
TC_5.0_SNP_0800_Smazání Snapshotu.js),先删除重复项减少不必要的加载。再将所有测试拆分为多个小批次,分阶段执行,避免一次性加载过多测试占用内存。关闭非必要的Cypress功能:如果不需要测试视频,在cypress.json中设置
"video": false;同时可设置"screenshotsFolder": false禁用自动截图,或仅在测试失败时保存截图,以此降低内存消耗。升级服务器内存:如果新机器本身内存容量不足,直接增加物理内存是最彻底的解决方案,确保系统有足够资源支撑Cypress和Chrome的运行。
启用并行测试:若使用的Cypress版本支持,通过
cypress run --parallel命令将测试分配到多个Chrome进程中并行执行,分散单进程的内存压力。
内容的提问来源于stack exchange,提问作者Tomasito
相关产品推荐
相关产品推荐

