Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

130
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!