/
mocha_test.coffee
1330 lines (1085 loc) · 30.8 KB
/
mocha_test.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
fs = require "fs"
should = require "should"
clone = require "lodash/clone"
{ stringify } = JSON
pkg = JSON.parse fs.readFileSync("package.json")
nodeCache = require "../"
{ randomNumber, randomString, diffKeys } = require "./helpers"
localCache = new nodeCache({
stdTTL: 0
})
localCacheNoClone = new nodeCache({
stdTTL: 0,
useClones: false,
checkperiod: 0
})
localCacheMaxKeys = new nodeCache({
maxKeys: 2
})
localCacheTTL = new nodeCache({
stdTTL: 0.3,
checkperiod: 0
})
localCacheNoDelete = new nodeCache({
stdTTL: 0.3,
checkperiod: 0
deleteOnExpire: false
})
localCacheMset = new nodeCache({
stdTTL: 0
})
BENCH = {}
# just for testing disable the check period
localCache._killCheckPeriod()
# store test state
state = {}
describe "`#{pkg.name}@#{pkg.version}` on `node@#{process.version}`", () ->
after ->
txt = "Benchmark node@#{process.version}:"
for type, ops of BENCH
txt += "\n - #{type}: #{ops.toFixed(1)} ops/s"
console.log txt
return
describe "general sync-style", () ->
before () ->
localCache.flushAll()
state =
start: clone localCache.getStats()
value: randomString 100
value2: randomString 100
value3: randomString 100
key: randomString 10
obj:
a: 1
b:
x: 2
y: 3
otp: randomString 10
return
it "set key", () ->
res = localCache.set state.key, state.value, 0
true.should.eql res
1.should.eql localCache.getStats().keys - state.start.keys
return
it "get key", () ->
res = localCache.get state.key
state.value.should.eql res
return
it "get key names", () ->
res = localCache.keys()
[state.key].should.eql res
return
it "has key", () ->
res = localCache.has(state.key)
res.should.eql true
return
it "does not have key", () ->
res = localCache.has('non existing key')
res.should.eql false
return
it "delete an undefined key", () ->
count = localCache.del "xxx"
0.should.eql count
return
it "take key", () ->
# make sure we are starting fresh
res = localCache.has("otp")
res.should.eql false
# taking a non-exitent value should be fine
res = localCache.take("otp")
should.not.exist(res)
# check if otp insertion suceeded
res = localCache.set "otp", state.otp, 0
true.should.eql res
# are we able to check the presence of the key?
res = localCache.has("otp")
res.should.eql true
# not once, but twice?
# This proves that keys can be accessed as many times as required, but
# not the value. The `take()` method makes the values as single-read, not the keys.
res = localCache.has("otp")
res.should.eql true
# take the value
otp = localCache.take("otp")
otp.should.eql state.otp
# key should not be present anymore once the value is read
res = localCache.has("otp")
res.should.eql false
# and, re-insertions are not probhitied
res = localCache.set "otp", "some other value"
true.should.eql res
# should be able take the value again
otp = localCache.take("otp")
otp.should.eql "some other value"
# key should not be present anymore, again
res = localCache.has("otp")
res.should.eql false
return
it "take key with falsy values", () ->
# make sure we are starting fresh
res = localCache.has("otp")
res.should.eql false
# insert a falsy value and take it
res = localCache.set "otp", 0
true.should.eql res
otp = localCache.take("otp")
otp.should.eql 0
# key should not exist anymore
res = localCache.has("otp")
res.should.eql false
return
it "update key (and get it to check if the update worked)", () ->
res = localCache.set state.key, state.value2, 0
true.should.eql res
# check if the update worked
res = localCache.get state.key
state.value2.should.eql res
# stats should not have changed
1.should.eql localCache.getStats().keys - state.start.keys
return
it "delete the defined key", () ->
localCache.once "del", (key, val) ->
state.key.should.eql key
state.value2.should.eql val
return
count = localCache.del state.key
1.should.eql count
# check stats
0.should.eql localCache.getStats().keys - state.start.keys
return
it "delete multiple keys (after setting them)", () ->
keys = ["multiA", "multiB", "multiC"]
# set the keys
keys.forEach (key) ->
res = localCache.set key, state.value3
true.should.eql res
return
# check the keys
keys.forEach (key) ->
res = localCache.get key
state.value3.should.eql res
return
# delete 2 of those keys
count = localCache.del keys[0...2]
2.should.eql count
# try to get the deleted keys
keys[0...2].forEach (key) ->
res = localCache.get key
should(res).be.undefined()
return
# get the not deleted key
res = localCache.get keys[2]
state.value3.should.eql res
# delete this key, too
count = localCache.del keys[2]
1.should.eql count
# try get the deleted key
res = localCache.get keys[2]
should(res).be.undefined()
# re-deleting the keys should not have to delete an actual key
count = localCache.del keys
0.should.eql count
return
it "set a key to 0", () ->
res = localCache.set "zero", 0
true.should.eql res
return
it "get previously set key", () ->
res = localCache.get "zero"
0.should.eql res
return
it "set a key to an object clone", () ->
res = localCache.set "clone", state.obj
true.should.eql res
return
it "get cloned object", () ->
res = localCache.get "clone"
# should not be === equal
state.obj.should.not.equal res
# but should deep equal
state.obj.should.eql res
res.b.y = 42
res2 = localCache.get "clone"
state.obj.should.eql res2
return
it "test promise storage (fulfill before adding to cache)", (done) ->
deferred_value = "Some deferred value"
if Promise?
p = new Promise (fulfill, reject) ->
fulfill deferred_value
return
p.then (value) ->
deferred_value.should.eql value
return
localCache.set "promise", p
q = localCache.get "promise"
q.then (value) ->
done()
return
else
if not process.env.SILENT_MODE?
console.log "No Promises available in this node version (#{process.version})"
this.skip()
return
it "test promise storage (fulfill after adding to cache)", (done) ->
deferred_value = "Some deferred value"
if Promise?
called = 0
callStub = () ->
called++
if called is 2
done()
return
p = new Promise (fulfill, reject) ->
fulfiller = () ->
fulfill deferred_value
return
setTimeout fulfiller, 250
return
p.then (value) ->
deferred_value.should.eql value
callStub()
return
localCache.set "promise", p
q = localCache.get "promise"
q.then (value) ->
deferred_value.should.eql value
callStub()
return
else
if not process.env.SILENT_MODE?
console.log "No Promises available in this node version (#{process.version})"
this.skip()
return
it "test es6 map", () ->
unless Map?
if not process.env.SILENT_MODE?
console.log "No Maps available in this node version (#{process.version})"
this.skip()
return
key = randomString 10
map = new Map([ ["firstkey", "firstvalue"], ["2ndkey", "2ndvalue"], ["thirdkey", "thirdvalue"] ])
localCache.set key, map
map.set "fourthkey", "fourthvalue"
cached_map = localCache.get key
should( cached_map.get("2ndkey") ).eql "2ndvalue"
should( cached_map.get "fourthkey" ).be.undefined()
return
it "test `useClones = true` with an Object", () ->
key = randomString 10
value =
a: 123
b: 456
c = 789
localCache.set key, value
value.a = c
value.should.not.be.eql localCache.get(key)
return
it "test `useClones = false` with an Object", () ->
key = randomString 10
value =
a: 123
b: 456
c = 789
localCacheNoClone.set key, value
value.a = c
should( value is localCacheNoClone.get(key) ).be.true()
return
return
describe "max key amount", () ->
before () ->
state =
key1: randomString(10)
key2: randomString(10)
key3: randomString(10)
value1: randomString(10)
value2: randomString(10)
value3: randomString(10)
return
it "exceed max key size", () ->
setKey = localCacheMaxKeys.set(state.key1, state.value1, 0)
true.should.eql setKey
setKey2 = localCacheMaxKeys.set(state.key2, state.value2, 0)
true.should.eql setKey2
(() -> localCacheMaxKeys.set(state.key3, state.value3, 0)).should.throw({
name: "ECACHEFULL"
message: "Cache max keys amount exceeded"
})
return
it "remove a key and set another one", () ->
del = localCacheMaxKeys.del(state.key1)
1.should.eql del
setKey3 = localCacheMaxKeys.set(state.key3, state.value3, 0)
true.should.eql setKey3
return
return
describe "correct and incorrect key types", () ->
describe "number", () ->
before () ->
state =
keys: []
val: randomString 20
for [1..10]
state.keys.push randomNumber 100000
return
it "set", () ->
for key in state.keys
res = localCache.set key, state.val
true.should.eql res
return
it "get", () ->
res = localCache.get state.keys[0]
state.val.should.eql res
return
it "mget", () ->
res = localCache.mget state.keys[0..1]
# generate prediction
prediction = {}
prediction[state.keys[0]] = state.val
prediction[state.keys[1]] = state.val
prediction.should.eql res
return
it "del single", () ->
count = localCache.del state.keys[0]
1.should.eql count
return
it "del multi", () ->
count = localCache.del state.keys[1..2]
2.should.eql count
return
it "ttl", (done) ->
success = localCache.ttl state.keys[3], 0.3
true.should.eql success
res = localCache.get state.keys[3]
state.val.should.eql res
setTimeout(() ->
res = localCache.get state.keys[3]
should.not.exist res
done()
return
, 400)
return
it "getTtl", () ->
now = Date.now()
success = localCache.ttl state.keys[4], 0.5
true.should.eql success
ttl = localCache.getTtl state.keys[4]
(485 < (ttl - now) < 510).should.eql true
return
after () ->
localCache.flushAll false
return
return
describe "string", () ->
before () ->
state =
keys: []
val: randomString 20
for [1..10]
state.keys.push randomString 10
return
it "set", () ->
for key in state.keys
res = localCache.set key, state.val
true.should.eql res
return
it "get", () ->
res = localCache.get state.keys[0]
state.val.should.eql res
return
it "mget", () ->
res = localCache.mget state.keys[0..1]
# generate prediction
prediction = {}
prediction[state.keys[0]] = state.val
prediction[state.keys[1]] = state.val
prediction.should.eql res
return
it "del single", () ->
count = localCache.del state.keys[0]
1.should.eql count
return
it "del multi", () ->
count = localCache.del state.keys[1..2]
2.should.eql count
return
it "ttl", (done) ->
success = localCache.ttl state.keys[3], 0.3
true.should.eql success
res = localCache.get state.keys[3]
state.val.should.eql res
setTimeout(() ->
res = localCache.get state.keys[3]
should.not.exist res
done()
return
, 400)
return
it "getTtl", () ->
now = Date.now()
success = localCache.ttl state.keys[4], 0.5
true.should.eql success
ttl = localCache.getTtl state.keys[4]
(485 < (ttl - now) < 510).should.eql true
return
return
describe "boolean - invalid type", () ->
before () ->
state =
keys: [true, false]
val: randomString 20
return
it "set sync-style", () ->
(() -> localCache.set(state.keys[0], state.val)).should.throw({
name: "EKEYTYPE"
message: "The key argument has to be of type `string` or `number`. Found: `boolean`"
})
return
it "get sync-style", () ->
(() -> localCache.get(state.keys[0])).should.throw({
name: "EKEYTYPE"
message: "The key argument has to be of type `string` or `number`. Found: `boolean`"
})
return
it "mget sync-style", () ->
(() -> localCache.mget(state.keys)).should.throw({
name: "EKEYTYPE"
message: "The key argument has to be of type `string` or `number`. Found: `boolean`"
})
return
it "del single sync-style", () ->
(() -> localCache.del(state.keys[0])).should.throw({
name: "EKEYTYPE"
message: "The key argument has to be of type `string` or `number`. Found: `boolean`"
})
return
it "del multi sync-style", () ->
(() -> localCache.del(state.keys)).should.throw({
name: "EKEYTYPE"
message: "The key argument has to be of type `string` or `number`. Found: `boolean`"
})
return
it "ttl sync-style", () ->
(() -> localCache.ttl(state.keys[0], 10)).should.throw({
name: "EKEYTYPE"
message: "The key argument has to be of type `string` or `number`. Found: `boolean`"
})
return
it "getTtl sync-style", () ->
(() -> localCache.getTtl(state.keys[0])).should.throw({
name: "EKEYTYPE"
message: "The key argument has to be of type `string` or `number`. Found: `boolean`"
})
return
describe "object - invalid type", () ->
before () ->
state =
keys: [{ a: 1 }, { b: 2 }]
val: randomString 20
return
it "set sync-style", () ->
(() -> localCache.set(state.keys[0], state.val)).should.throw({
name: "EKEYTYPE"
message: "The key argument has to be of type `string` or `number`. Found: `object`"
})
return
it "get sync-style", () ->
(() -> localCache.get(state.keys[0])).should.throw({
name: "EKEYTYPE"
message: "The key argument has to be of type `string` or `number`. Found: `object`"
})
return
it "mget sync-style", () ->
(() -> localCache.mget(state.keys)).should.throw({
name: "EKEYTYPE"
message: "The key argument has to be of type `string` or `number`. Found: `object`"
})
return
it "del single sync-style", () ->
(() -> localCache.del(state.keys[0])).should.throw({
name: "EKEYTYPE"
message: "The key argument has to be of type `string` or `number`. Found: `object`"
})
return
it "del multi sync-style", () ->
(() -> localCache.del(state.keys)).should.throw({
name: "EKEYTYPE"
message: "The key argument has to be of type `string` or `number`. Found: `object`"
})
return
it "ttl sync-style", () ->
(() -> localCache.ttl(state.keys[0], 10)).should.throw({
name: "EKEYTYPE"
message: "The key argument has to be of type `string` or `number`. Found: `object`"
})
return
it "getTtl sync-style", () ->
(() -> localCache.getTtl(state.keys[0])).should.throw({
name: "EKEYTYPE"
message: "The key argument has to be of type `string` or `number`. Found: `object`"
})
return
return
describe "flush", () ->
before () ->
state =
n: 0
count: 100
startKeys: localCache.getStats().keys
keys: []
val: randomString 20
return
it "set keys", () ->
for [1..state.count]
key = randomString 7
state.keys.push key
state.keys.forEach (key) ->
localCache.set key
state.n++
return
state.count.should.eql state.n
(state.startKeys + state.count).should.eql localCache.getStats().keys
return
it "flush keys", () ->
localCache.flushAll false
0.should.eql localCache.getStats().keys
{}.should.eql localCache.data
return
return
describe "flushStats", () ->
cache = null
before () ->
cache = new nodeCache()
return
it "set cache and flush stats value", () ->
key = randomString 10
value = randomString 10
res = cache.set key,value
true.should.eql res
1.should.eql cache.getStats().keys
cache.flushStats()
0.should.eql cache.getStats().keys
cache.get key
1.should.eql cache.getStats().hits
cache.get randomString 10
1.should.eql cache.getStats().misses
return
return
describe "many", () ->
before () ->
state =
n: 0
count: 100000
keys: []
val: randomString 20
for [1..state.count]
key = randomString 7
state.keys.push key
return
describe "delete", () ->
this.timeout(0)
before () ->
# don't override state because we still need `state.keys`
state.n = 0
return
before () ->
state =
n: 0
count: 100000
keys: []
val: randomString 20
for [1..state.count]
key = randomString 7
state.keys.push key
localCache.set(key, state.val)
return
it "delete all previously set keys", () ->
for i in [0...state.count]
1.should.eql localCache.del state.keys[i]
state.n++
state.n.should.eql state.count
localCache.getStats().keys.should.eql 0
return
it "delete keys again; should not delete anything", () ->
for i in [0...state.count]
0.should.eql localCache.del state.keys[i]
state.n++
state.n.should.eql state.count*2
localCache.getStats().keys.should.eql 0
return
describe "stats", () ->
before () ->
state =
n: 0
start: clone localCache.getStats()
count: 5
keylength: 7
valuelength: 50
keys: []
values: []
for [1..state.count*2]
key = randomString state.keylength
value = randomString state.valuelength
state.keys.push key
state.values.push value
true.should.eql localCache.set key, value, 0
state.n++
return
it "get and remove `count` elements", () ->
for i in [1..state.count]
state.values[i].should.eql localCache.get state.keys[i]
state.n++
for i in [1..state.count]
1.should.eql localCache.del state.keys[i]
state.n++
after = localCache.getStats()
diff = diffKeys after, state.start
diff.hits.should.eql 5
diff.keys.should.eql 5
diff.ksize.should.eql state.count * state.keylength
diff.vsize.should.eql state.count * state.valuelength
return
it "generate `count` misses", () ->
for i in [1..state.count]
# 4 char key should not exist
should(localCache.get "xxxx").be.undefined()
state.n++
after = localCache.getStats()
diff = diffKeys after, state.start
diff.misses.should.eql 5
return
it "check successful runs", () ->
state.n.should.eql 5 * state.count
return
return
describe "multi", () ->
before () ->
state =
n: 0
count: 100
startKeys: localCache.getStats().keys
value: randomString 20
keys: []
for [1..state.count]
key = randomString 7
state.keys.push key
for key in state.keys
localCache.set key, state.value, 0
state.n++
return
it "generate a sub-list of keys", () ->
state.getKeys = state.keys.splice 50, 5
return
it "generate prediction", () ->
state.prediction = {}
for key in state.getKeys
state.prediction[key] = state.value
return
it "try to mget with a single key", () ->
(() -> localCache.mget(state.getKeys[0])).should.throw({
name: "EKEYSTYPE",
message: "The keys argument has to be an array."
})
state.n++
return
it "mget the sub-list", () ->
state.prediction.should.eql localCache.mget state.getKeys
state.n++
return
it "delete keys in the sub-list", () ->
state.getKeys.length.should.eql localCache.del state.getKeys
state.n++
return
it "try to mget the sub-list again", () ->
{}.should.eql localCache.mget state.getKeys
state.n++
return
it "check successful runs", () ->
state.n.should.eql state.count + 4
return
return
describe "ttl", () ->
before () ->
state =
n: 0
val: randomString 20
key1: "k1_#{randomString 20}"
key2: "k2_#{randomString 20}"
key3: "k3_#{randomString 20}"
key4: "k4_#{randomString 20}"
key5: "k5_#{randomString 20}"
key6: "k6_#{randomString 20}"
now: Date.now()
state.keys = [state.key1, state.key2, state.key3, state.key4, state.key5]
return
describe "has validates expired ttl", () ->
it "set a key with ttl", () ->
true.should.eql localCacheTTL.set state.key6, state.val, 0.7
return
it "check this key immediately", () ->
true.should.eql localCacheTTL.has state.key6
return
it "before it times out", (done) ->
setTimeout(() ->
state.n++
res = localCacheTTL.has state.key6
res.should.eql true
state.val.should.eql localCacheTTL.get state.key6
done()
return
, 20)
return
it "and after it timed out", (done) ->
setTimeout(() ->
res = localCacheTTL.has state.key6
res.should.eql false
state.n++
should(localCacheTTL.get state.key6).be.undefined()
done()
return
, 800)
return
it "set a key with ttl", () ->
res = localCache.set state.key1, state.val, 0.7
true.should.eql res
ts = localCache.getTtl state.key1
if state.now < ts < state.now + 300
throw new Error "Invalid timestamp"
return
it "check this key immediately", () ->
state.val.should.eql localCache.get state.key1
return
it "before it times out", (done) ->
setTimeout(() ->
state.n++
res = localCache.has state.key1
res.should.eql true
state.val.should.eql localCache.get state.key1
done()
return
, 20)
return
it "and after it timed out", (done) ->
setTimeout(() ->
res = localCache.has state.key1
res.should.eql false
ts = localCache.getTtl state.key1
should.not.exist ts
state.n++
should(localCache.get state.key1).be.undefined()
done()
return
, 700)
return
it "set another key with ttl", () ->
res = localCache.set state.key2, state.val, 0.5
true.should.eql res
return
it "check this key immediately", () ->
res = localCache.get state.key2
state.val.should.eql res
return
it "before it times out", (done) ->
setTimeout(() ->
state.n++
state.val.should.eql localCache.get state.key2
done()
return
, 20)
return
it "and after it timed out, too", (done) ->
setTimeout(() ->
ts = localCache.getTtl state.key2
should.not.exist ts
state.n++
should(localCache.get state.key2).be.undefined()
done()
return
, 500)
return
describe "test the automatic check", (done) ->
innerState = null
before (done) ->
setTimeout(() ->
innerState =
startKeys: localCache.getStats().keys
key: "autotest"
val: randomString 20
done()
return
, 1000)
return
it "set a key with ttl", () ->
localCache.once "set", (key) ->
innerState.key.should.eql key
return
true.should.eql localCache.set innerState.key, innerState.val, 0.5
(innerState.startKeys + 1).should.eql localCache.getStats().keys
# event handler should have been fired
0.should.eql localCache.listeners("set").length
return
it "and check it's existence", () ->
innerState.val.should.eql localCache.get innerState.key