首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Docker CI不能与mongodb-memory-server一起使用

Docker CI不能与mongodb-memory-server一起使用
EN

Stack Overflow用户
提问于 2021-06-05 17:52:37
回答 1查看 70关注 0票数 3

我使用mongodb-memory-server在mongo中测试了一些存储库功能,并在我的本地机器上成功地运行了单元测试,但是当这段代码被推到GitHub中时,它运行失败。我不确定问题是关于docker配置还是关于mongodb-memory-server版本。以下是来自GitHub的日志:

代码语言:javascript
复制
9W45p5LM91Vj","tmpDir":{"name":"/tmp/mongo-mem--188-9W45p5LM91Vj"},"uri":"mongodb://127.0.0.1:42823/d791a878-09ac-4ccc-896d-ea603e2676ad?"}
2021-06-05T09:45:33.351Z MongoMS:MongoBinary MongoBinary options: {
  "downloadDir": "/__w/son-git-test/son-git-test/node_modules/.cache/mongodb-memory-server/mongodb-binaries",
  "platform": "linux",
  "arch": "x64",
  "version": "4.2.8",
  "checkMD5": false
}
2021-06-05T09:45:33.356Z MongoMS:getos Trying LSB-Release
2021-06-05T09:45:33.372Z MongoMS:getos Trying OS-Release
2021-06-05T09:45:33.375Z MongoMS:MongoBinaryDownloadUrl Using "mongodb-linux-x86_64-debian92-4.2.8.tgz" as the Archive String
2021-06-05T09:45:33.375Z MongoMS:MongoBinaryDownloadUrl Using "https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu1804-4.2.8.tgz" as the Download-URL
2021-06-05T09:45:33.377Z MongoMS:MongoBinaryDownload Downloading: "https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu1804-4.2.8.tgz"
2021-06-05T09:45:33.377Z MongoMS:MongoBinaryDownload trying to download https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu1804-4.2.8.tgz
2021-06-05T09:45:34.756Z MongoMS:MongoBinaryDownload moved /__w/son-git-test/son-git-test/node_modules/.cache/mongodb-memory-server/mongodb-binaries/mongodb-linux-x86_64-ubuntu1804-4.2.8.tgz.downloading to /__w/son-git-test/son-git-test/node_modules/.cache/mongodb-memory-server/mongodb-binaries/mongodb-linux-x86_64-ubuntu1804-4.2.8.tgz
2021-06-05T09:45:34.757Z MongoMS:MongoBinaryDownload extract(): /__w/son-git-test/son-git-test/node_modules/.cache/mongodb-memory-server/mongodb-binaries/4.2.8
2021-06-05T09:45:37.293Z MongoMS:MongoBinary MongoBinary: Download lock removed
2021-06-05T09:45:37.294Z MongoMS:MongoBinary MongoBinary: Mongod binary path: "/__w/son-git-test/son-git-test/node_modules/.cache/mongodb-memory-server/mongodb-binaries/4.2.8/mongod"
2021-06-05T09:45:37.309Z MongoMS:MongoInstance Mongo[42823]: Called MongoInstance._launchKiller(parent: 188, child: 203):
2021-06-05T09:45:37.323Z MongoMS:MongoInstance Mongo[42823]: STDERR: /__w/son-git-test/son-git-test/node_modules/.cache/mongodb-memory-server/mongodb-binaries/4.2.8/mongod: error while loading shared libraries: libcurl.so.4: cannot open shared object file: No such file or directory

2021-06-05T09:45:37.324Z MongoMS:MongoInstance Mongo[42823]: Mongod instance closed with an non-0 code!
2021-06-05T09:45:37.324Z MongoMS:MongoInstance Mongo[42823]: CLOSE: 127
2021-06-05T09:45:37.325Z MongoMS:MongoInstance Mongo[42823]: MongodbInstance: Instance has failed: Mongod instance closed with code "127"
2021-06-05T09:45:37.331Z MongoMS:MongoMemoryServer Called MongoMemoryServer.stop() method
2021-06-05T09:45:37.331Z MongoMS:MongoMemoryServer Called MongoMemoryServer.ensureInstance() method
2021-06-05T09:45:37.349Z MongoMS:MongoInstance Mongo[42823]: [MongoKiller]: exit - [null,"SIGTERM"]
FAIL src/squid/squid.controller.spec.ts (9.945 s)
  ● Console

    console.log
      before each

      at Object.<anonymous> (squid/squid.controller.spec.ts:19:13)

    console.log
      Downloading MongoDB 4.2.8: 0 % (0mb / 126.5mb)

      at MongoBinaryDownload.Object.<anonymous>.MongoBinaryDownload.printDownloadProgress (../node_modules/mongodb-memory-server-core/src/util/MongoBinaryDownload.ts:424:15)

  ● SquidController › should be defined

    Failed: "Mongod instance closed with code \"127\""

      16 |   let controller: SquidController;
      17 |
    > 18 |   beforeEach(async () => {
         |   ^
      19 |     console.log('before each');
      20 |     const module: TestingModule = await Test.createTestingModule({
      21 |       imports: [

      at Env.beforeEach (../node_modules/jest-jasmine2/build/jasmineAsyncInstall.js:46:24)
      at Suite.<anonymous> (squid/squid.controller.spec.ts:18:3)
      at Object.<anonymous> (squid/squid.controller.spec.ts:15:1) 

下面是gitflow配置:

代码语言:javascript
复制
name: Code quality
on:
  pull_request:
    branches:
      - develop
  push:
    branches:
      - develop

defaults:
  run:
    shell: bash

jobs:
  Code-Quality:
    name: Code quality
    runs-on: ubuntu-latest
    container: node:lts-slim
    steps:
      - uses: actions/checkout@v2
      - name: Install dependency
        run: yarn install --frozen-lockfile
      - name: Check lint and format
        run: |
          yarn format:check
          yarn lint:check
      - name: checking unit test
        run: yarn test

下面是单元测试代码:

代码语言:javascript
复制
import { Test, TestingModule } from '@nestjs/testing';
import { MongooseModule } from '@nestjs/mongoose';

import { SquidController } from './squid.controller';
import { SquidService } from './squid.service';
import {
  closeInMongodConnection,
  rootMongooseTestModule,
} from '../test-utils/mongo/MongooseTestModule';
import { SquidSchema } from './model/squid.schema';

// May require additional time for downloading MongoDB binaries
jasmine.DEFAULT_TIMEOUT_INTERVAL = 600000;

describe('SquidController', () => {
  let controller: SquidController;

  beforeEach(async () => {
    console.log('before each');
    const module: TestingModule = await Test.createTestingModule({
      imports: [
        rootMongooseTestModule(),
        MongooseModule.forFeature([{ name: 'Squid', schema: SquidSchema }]),
      ],
      controllers: [SquidController],
      providers: [SquidService],
    }).compile();

    controller = module.get<SquidController>(SquidController);
  });

  it('should be defined', () => {
    expect(controller).toBeDefined();
  });

  afterAll(async () => {
    await closeInMongodConnection();
  });
});
EN

回答 1

Stack Overflow用户

发布于 2021-06-07 18:48:05

经过搜索,我找到了问题所在。此问题与Node版本相关。Mongo还没有Node slim/alpine的构建版本。我们可以通过更新节点镜像来修复:(容器:节点:14.17.0)

代码语言:javascript
复制
name: Code quality
on:
  pull_request:
    branches:
      - develop
  push:
    branches:
      - develop

defaults:
  run:
    shell: bash

jobs:
  Code-Quality:
    name: Code quality
    runs-on: ubuntu-latest
    container: node:14.17.0
    steps:
      - uses: actions/checkout@v2
      - name: Install dependency
        run: yarn install --frozen-lockfile
      - name: Check lint and format
        run: |
          yarn format:check
          yarn lint:check
      - name: checking unit test
        run: yarn test
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67848339

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档