Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

128
Vistas
Mongoose Memory Sever insertOne Buffering Timed Out

I'm currently trying to write some tests for my Rest-API in NodeJS. For that i've used the Mongoose Memory Server until now and it worked smoothly. But now i've added a new model to my project and Mongoose is really struggling to insert the data into the memory db.

I'm always getting 'buffering timed out' as error when running the test.

That's my DB-Util which creates the connection before each test:

const mongoose = require("mongoose");
const { MongoMemoryServer } = require("mongodb-memory-server");

// Extend the default timeout so MongoDB binaries can download
jest.setTimeout(60000);

// List all of your collection names here - I'll add some examples
const COLLECTIONS = [
  "users",
  "roles",
  "dashboards",
  "querydatas",
  "snapshots",
  "tabs",
];

class DBManager {
  constructor() {
    this.db = null;
    this.connection = null;
  }

  // Spin up a new in-memory mongo instance
  async start() {
    this.server = await MongoMemoryServer.create();
    const url = await this.server.getUri();
    await mongoose.connect(url, {
      useNewUrlParser: true,
      useUnifiedTopology: true,
    });
    this.connection = mongoose.connection;
  }

  // Close the connection and halt the mongo instance
  stop() {
    this.connection.close();
    return this.server.stop();
  }

  // Remove all documents from the entire database - useful between tests
  async cleanup() {
    const collections = mongoose.connection.collections;
    for (const key in collections) {
      const collection = collections[key];
      await collection.deleteMany();
    }
  }
}

module.exports = DBManager;

And this is the test which won't work:

afterAll(() => dbman.stop());
beforeAll(() => dbman.start());
afterEach(() => dbman.cleanup());
beforeEach(
  () => (this.grafanaServiceMock = rewire("../../services/grafana.service"))
);

describe("working with snapshots", () => {
  it("should create a snapshot", async () => {
    this.grafanaServiceMock.__set__("grafanaRestService", {
      createSnapshotForDashboard: () => {
        return Promise.resolve(getSnapshotData());
      },
      getSnapshotByKey: () => {
        return Promise.resolve(getSnapshotByKeyData());
      },
    });

    const snapshot = await this.grafanaServiceMock.createSnapshot(
      getDashboardData(),
      4
    );
    expect(snapshot).toEqual(getCreatedSnapshotData());
  });
});

Can someone tell me what i'm doing wrong?

Anyone here with an idea?

Thanks in advance.

about 4 years ago · Santiago Gelvez
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda