Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expired value #302

Open
gomez-git opened this issue Dec 28, 2022 · 1 comment
Open

Expired value #302

gomez-git opened this issue Dec 28, 2022 · 1 comment

Comments

@gomez-git
Copy link

gomez-git commented Dec 28, 2022

Hello!

I try to test my REST API with jest, using Fastify, Bull and Node-Cache.

I have some separated test files, and in previous file using cache is ok, but when I try to use it again I stuck some strange situation that value in array is expired, I try to debug this, log cache instance and link to array and get true when compare them. I import cache instance in test file and see this value all the time, but in my another module it doesn't appear at all. If I move this test to previous file it works how I expect. Try to flush and close cache but not helped.

Can someone help? Any ideas?

Code:

cache.js

import NodeCache from 'node-cache';

const cache = new NodeCache({ useClones: false });

export default cache;

controller.js

import cache from '../utils/cache.js';
...
const account = cache.get(name);
account.hooks[key].push(hookDto);
console.log(account.hooks) // { add: [], update: [], delete: [], restore: [ 32197627 ] }

service.js

import cache from '../utils/cache.js';
...
const { hooks } = cache.get(name);
console.log(account.hooks) // { add: [], update: [], delete: [], restore: [] }

test.js

import cache from '../utils/cache.js';
...
it('Restore hook', async () => {
    console.log(cache.get(name).hooks);  // { add: [], update: [], delete: [], restore: [] }
    const payload = readFile('amo', 'restore-webhook-1.txt').slice(0, -1);
    const response = await app.inject({
      method: 'POST',
      url: '/api/v2/webhook/amo',
      headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8' },
      payload,
    });

    expect(response.statusCode).toBe(204);
    console.log(cache.get(name).hooks);  // { add: [], update: [], delete: [], restore: [ 32197627 ] }
    await waitJob(name, 'amo-webhook-1'); // after this restore array must be empty
    console.log(cache.get(name).hooks);  // { add: [], update: [], delete: [], restore: [ 32197627 ] }
})
@deepam-kapur
Copy link

Can I work on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants