小编Wil*_*ang的帖子

Node.js:Jest + redis.quit()但是打开句柄警告仍然存在

我正在尝试使用redis和jest运行集成测试.

它始终抛出"Jest检测到以下1个打开的句柄可能使Jest退出:"与--detectOpenHandles一起运行时出错.

它没有挂起,因此套接字正在关闭,但是如何编写它以便它不会抛出该警告?

我的代码

import redis from 'redis';
let red: redis.RedisClient;

beforeAll(() => {
    red = redis.createClient();
});

afterAll((done) => {
    red.quit(() => {
        done();
    });
});

test('redis', (done) => {
    red.set('a', 'b', (err, data) => {
        console.log(err);
        red.get('a', (err, data) => {
            console.log(data);
            done();
        });
    });

});
Run Code Online (Sandbox Code Playgroud)

警告

Jest has detected the following 1 open handle potentially keeping Jest from exiting:

?  TCPWRAP

    3 |
    4 | beforeAll(() => {
    > 5 |     red = redis.createClient();
        |                 ^
    6 …
Run Code Online (Sandbox Code Playgroud)

node.js node-redis jestjs

7
推荐指数
1
解决办法
726
查看次数

将装饰器的函数传递给Python RQ

如何将装饰器的功能传递给工作?

我有一个装饰器,可以使用该功能来运行作业。

@job
def queueFunction(passedFunction, *args, **kwargs):
    # Do some stuff
    passedFunction(*args, **kwargs)

def myDecorator(async=True):
    def wrapper(function):
        def wrappedFunc(*args, **kwargs):
            data = DEFAULT_DATA
            if async:
                queueFunction.delay(function, *args, **kwargs)
            else:
                data = queueFunction(function, *args, **kwargs)
            return data
        return wrappedFunc
    return wrapper
Run Code Online (Sandbox Code Playgroud)

尝试使用时出现错误。

Can't pickle <function Model.passedFunction at 0x7f410ad4a048>: it's not the same object as modelInstance.models.Model.passedFunction
Run Code Online (Sandbox Code Playgroud)

使用Python 3.4

python decorator python-3.x

3
推荐指数
1
解决办法
365
查看次数

标签 统计

decorator ×1

jestjs ×1

node-redis ×1

node.js ×1

python ×1

python-3.x ×1