<commit_before>var assert = require('assert');
var async = require('async');
var sinon = require('sinon');
var support = require('./support');
var check_err = support.check_err;
var caching = require('../index').caching;
var multi_caching = require('../index').multi_caching;
var memory_store = require('../lib/stores/memory');

var methods = {
    get_widget: function(name, cb) {
        cb(null, {name: name});
    }
};

describe("multi_caching", function() {
    var memory_cache;
    var memory_cache2;
    var memory_cache3;
    var multi_cache;
    var key;
    var memory_ttl;
    var name;
    var ttl = 5;

    beforeEach(function() {
        memory_ttl = 0.1;

        memory_cache = caching({store: 'memory', ttl: memory_ttl});
        memory_cache2 = caching({store: 'memory', ttl: memory_ttl});
        memory_cache3 = caching({store: 'memory', ttl: memory_ttl});

        key = support.random.string(20);
        name = support.random.string();
    });

    describe("get(), set(), del()", function() {
        var value;

        beforeEach(function() {
            multi_cache = multi_caching([memory_cache, memory_cache2, memory_cache3]);
            key = support.random.string(20);
            value = support.random.string();
        });

        describe("set()", function() {
            it("lets us set data in all caches", function(done) {
                multi_cache.set(key, value, ttl, function(err) {
                    check_err(err);
                    memory_cache.get(key, function(err, result) {
                        assert.equal(result, value);

                        memory_cache2.get(key, function(err, result) {
                            check_err(err);
                            assert.equal(result, value);

                            memory_cache3.get(key, function(err, result) {
                                check_err(err);
                                assert.equal(result, value);
                                done();
                            });
                        });
                    });
                });
            });

            it("lets us set data without a callback", function(done) {
                multi_cache.set(key, value, ttl);
                setTimeout(function() {
                    multi_cache.get(key, function(err, result) {
                        assert.equal(result, value);
                        memory_cache.get(key, function(err, result) {
                            assert.equal(result, value);

                            memory_cache2.get(key, function(err, result) {
                                check_err(err);
                                assert.equal(result, value);

                                memory_cache3.get(key, function(err, result) {
                                    check_err(err);
                                    assert.equal(result, value);
                                    done();
                                });
                            });
                        });
                    });
                }, 20);
            });

            it("lets us set data without a ttl or callback", function(done) {
                multi_cache.set(key, value);
                setTimeout(function() {
                    multi_cache.get(key, function(err, result) {
                        assert.equal(result, value);
                        memory_cache.get(key, function(err, result) {
                            assert.equal(result, value);

                            memory_cache2.get(key, function(err, result) {
                                check_err(err);
                                assert.equal(result, value);

                                memory_cache3.get(key, function(err, result) {
                                    check_err(err);
                                    assert.equal(result, value);
                                    done();
                                });
                            });
                        });
                    });
                }, 20);
            });
        });

        describe("get()", function() {
            it("gets data from first cache that has it", function(done) {
                memory_cache3.set(key, value, ttl, function(err) {
                    check_err(err);

                    multi_cache.get(key, function(err, result) {
                        check_err(err);
                        assert.equal(result, value);
                        done();
                    });
                });
            });
        });

        describe("del()", function() {
            it("lets us delete data in all caches", function(done) {
                multi_cache.set(key, value, ttl, function(err) {
                    check_err(err);

                    multi_cache.del(key, function(err) {
                        check_err(err);

                        memory_cache.get(key, function(err, result) {
                            assert.ok(!result);

                            memory_cache2.get(key, function(err, result) {
                                check_err(err);
                                assert.ok(!result);

                                memory_cache3.get(key, function(err, result) {
                                    check_err(err);
                                    assert.ok(!result);
                                    done();
                                });
                            });
                        });
                    });
                });
            });

            it("lets us delete data without a callback", function(done) {
                multi_cache.set(key, value, ttl, function(err) {
                    check_err(err);

                    multi_cache.del(key);

                    setTimeout(function() {
                        memory_cache.get(key, function(err, result) {
                            assert.ok(!result);

                            memory_cache2.get(key, function(err, result) {
                                check_err(err);
                                assert.ok(!result);

                                memory_cache3.get(key, function(err, result) {
                                    check_err(err);
                                    assert.ok(!result);
                                    done();
                                });
                            });
                        });
                    });
                }, 10);
            });<commit_msg>Fix incorrect timeout location<commit_after>var assert = require('assert');
var async = require('async');
var sinon = require('sinon');
var support = require('./support');
var check_err = support.check_err;
var caching = require('../index').caching;
var multi_caching = require('../index').multi_caching;
var memory_store = require('../lib/stores/memory');

var methods = {
    get_widget: function(name, cb) {
        cb(null, {name: name});
    }
};

describe("multi_caching", function() {
    var memory_cache;
    var memory_cache2;
    var memory_cache3;
    var multi_cache;
    var key;
    var memory_ttl;
    var name;
    var ttl = 5;

    beforeEach(function() {
        memory_ttl = 0.1;

        memory_cache = caching({store: 'memory', ttl: memory_ttl});
        memory_cache2 = caching({store: 'memory', ttl: memory_ttl});
        memory_cache3 = caching({store: 'memory', ttl: memory_ttl});

        key = support.random.string(20);
        name = support.random.string();
    });

    describe("get(), set(), del()", function() {
        var value;

        beforeEach(function() {
            multi_cache = multi_caching([memory_cache, memory_cache2, memory_cache3]);
            key = support.random.string(20);
            value = support.random.string();
        });

        describe("set()", function() {
            it("lets us set data in all caches", function(done) {
                multi_cache.set(key, value, ttl, function(err) {
                    check_err(err);
                    memory_cache.get(key, function(err, result) {
                        assert.equal(result, value);

                        memory_cache2.get(key, function(err, result) {
                            check_err(err);
                            assert.equal(result, value);

                            memory_cache3.get(key, function(err, result) {
                                check_err(err);
                                assert.equal(result, value);
                                done();
                            });
                        });
                    });
                });
            });

            it("lets us set data without a callback", function(done) {
                multi_cache.set(key, value, ttl);
                setTimeout(function() {
                    multi_cache.get(key, function(err, result) {
                        assert.equal(result, value);
                        memory_cache.get(key, function(err, result) {
                            assert.equal(result, value);

                            memory_cache2.get(key, function(err, result) {
                                check_err(err);
                                assert.equal(result, value);

                                memory_cache3.get(key, function(err, result) {
                                    check_err(err);
                                    assert.equal(result, value);
                                    done();
                                });
                            });
                        });
                    });
                }, 20);
            });

            it("lets us set data without a ttl or callback", function(done) {
                multi_cache.set(key, value);
                setTimeout(function() {
                    multi_cache.get(key, function(err, result) {
                        assert.equal(result, value);
                        memory_cache.get(key, function(err, result) {
                            assert.equal(result, value);

                            memory_cache2.get(key, function(err, result) {
                                check_err(err);
                                assert.equal(result, value);

                                memory_cache3.get(key, function(err, result) {
                                    check_err(err);
                                    assert.equal(result, value);
                                    done();
                                });
                            });
                        });
                    });
                }, 20);
            });
        });

        describe("get()", function() {
            it("gets data from first cache that has it", function(done) {
                memory_cache3.set(key, value, ttl, function(err) {
                    check_err(err);

                    multi_cache.get(key, function(err, result) {
                        check_err(err);
                        assert.equal(result, value);
                        done();
                    });
                });
            });
        });

        describe("del()", function() {
            it("lets us delete data in all caches", function(done) {
                multi_cache.set(key, value, ttl, function(err) {
                    check_err(err);

                    multi_cache.del(key, function(err) {
                        check_err(err);

                        memory_cache.get(key, function(err, result) {
                            assert.ok(!result);

                            memory_cache2.get(key, function(err, result) {
                                check_err(err);
                                assert.ok(!result);

                                memory_cache3.get(key, function(err, result) {
                                    check_err(err);
                                    assert.ok(!result);
                                    done();
                                });
                            });
                        });
                    });
                });
            });

            it("lets us delete data without a callback", function(done) {
                multi_cache.set(key, value, ttl, function(err) {
                    check_err(err);

                    multi_cache.del(key);

                    setTimeout(function() {
                        memory_cache.get(key, function(err, result) {
                            assert.ok(!result);

                            memory_cache2.get(key, function(err, result) {
                                check_err(err);
                                assert.ok(!result);

                                memory_cache3.get(key, function(err, result) {
                                    check_err(err);
                                    assert.ok(!result);
                                    done();
                                });
                            });
                        });
                    }, 10);
                });
            });
{'fraction_non_alphanumeric': 0.10926873997096355, 'fraction_numerical': 0.004584702376404065, 'mean_word_length': 0.9896625114016419, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 24, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6116305', 'n_tokens_mistral': 3184, 'n_tokens_neox': 2949, 'n_words': 565}