我正在使用otj-pg-embedded对嵌入式postgres数据库运行一些测试。虽然测试在本地运行良好,但在由Gitlab-CI运行时会失败,并出现非法状态异常。Gitlab CI构建了它,并运行了不包含otj-pg-embedded的测试。
我已经注释掉了测试类的大部分内容,并将问题定位到:
public static SingleInstancePostgresRule pg = EmbeddedPostgresRules.singleInstance();import com.goldfinger.models.AuditLog;
import com.opentable.db.postgres.embedded.FlywayPreparer;
import com.opentable.db.postgres.junit.EmbeddedPostgresRules;
import com.opentable.db.postgres.junit.PreparedDbRule;
import org.junit.*;
import org.junit.runner.RunWith;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
public class SQLAuditRepositoryTest {
private static SQLAuditRepository sqlAuditRepository;
private static AuditLog auditLog_1;
private static AuditLog auditLog_2;
private static AuditLog auditLog_3;
private static List<AuditLog> auditLogList;
@ClassRule
public static SingleInstancePostgresRule pg = EmbeddedPostgresRules.singleInstance();
@Test
public void simpleTest() {
assert (2 == 2);
}
}这是堆栈跟踪:
java.lang.IllegalStateException: Process [/tmp/embedded-pg/PG-06e3a92a2edb6ddd6dbdf5602d0252ca/bin/initdb, -A, trust, -U, postgres, -D, /tmp/epg6584640257265165384, -E, UTF-8] failed
at com.opentable.db.postgres.embedded.EmbeddedPostgres.system(EmbeddedPostgres.java:626)
at com.opentable.db.postgres.embedded.EmbeddedPostgres.initdb(EmbeddedPostgres.java:240)
...
... many lines here
...
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
at java.lang.Thread.run(Thread.java:745)这是gitlab-ci.yml
image: java:latest
services:
- postgres:latest
before_script:
- export GRADLE_USER_HOME=`pwd`/.gradle
package:
stage: build
script:
- ./gradlew assemble
test:
stage: test
script:
- ./gradlew check
artifacts:
reports:
junit: build/test-results/test/*.xml任何帮助都将不胜感激。
发布于 2020-12-14 20:30:06
如果在升级到macOS 11.x+ (到BigSur)后停止
对于Mac用户(尤其是新的BigSur)来说,已经有一个issue可以解决这个问题。
目前还没有一个明确的“修复”,但我已经通过以下方式安装了postgresql:
brew install postgresql不确定这是否适用于其他操作系统。
发布于 2021-02-17 16:57:38
我在MacOS M1上使用嵌入式postgres运行测试时遇到了类似的问题:
java.lang.IllegalStateException: Process [/var/folders/g_/jxzv9glj0p13njlzpr9xtcfm0000gn/T/embedded-pg/PG-4f38c8a8b2500189835f8ec1b75de81b/bin/initdb, -A, trust, -U, postgres, -D, /var/folders/g_/jxzv9glj0p13njlzpr9xtcfm0000gn/T/pg-embedded-009358be-3e95-4dbe-aa7a-01a9008511cb-3277843270072134584/epg524445573999525527, -E, UTF-8] failed我复制粘贴了命令,并在shell上运行它:
/var/folders/g_/jxzv9glj0p13njlzpr9xtcfm0000gn/T/embedded-pg/PG-4f38c8a8b2500189835f8ec1b75de81b/bin/initdb -A trust -U postgres -D /var/folders/g_/jxzv9glj0p13njlzpr9xtcfm0000gn/T/pg-embedded-009358be-3e95-4dbe-aa7a-01a9008511cb-3277843270072134584/epg524445573999525527 -E UTF-8输出向我显示了一个提示:
Running bootstrap script ... 2021-02-17 08:18:21.008 WET [28692] FATAL: could not create shared memory segment: Cannot allocate memory
2021-02-17 08:18:21.008 WET [28692] DETAIL: Failed system call was shmget(key=5432001, size=56, 03600).
2021-02-17 08:18:21.008 WET [28692] HINT: This error usually means that PostgreSQL's request for a shared memory segment exceeded your kernel's SHMALL parameter. You might need to reconfigure the kernel with larger SHMALL.
The PostgreSQL documentation contains more information about shared memory configuration.
child process exited with exit code 1
initdb: removing contents of data directory "/var/folders/g_/jxzv9glj0p13njlzpr9xtcfm0000gn/T/pg-embedded-cbe6f5f8-24b2-4431-afec-6e7aeb1dbb5d-8656684715588054403/epg6904898061245880853"然后我在shell上运行:
sudo sysctl kern.sysv.shmmax=104857600
sudo sysctl kern.sysv.shmall=25600而且它起作用了。
发布于 2019-11-07 17:16:30
我在flyway/embedded-pg上也遇到了同样的问题。似乎临时文件在某一时刻被损坏了。重新启动将修复它(直到它再次发生),或者您可以删除/tmp/embedded-pg/中的PG-*目录
https://stackoverflow.com/questions/55958103
复制相似问题