@@ -615,63 +615,26 @@ describe "`#{pkg.name}@#{pkg.version}` on `node@#{process.version}`", () ->
615615 state .keys .push key
616616 return
617617
618- describe " BENCHMARK" , () ->
619- this .timeout (0 )
620- # hack so mocha always shows timing information
621- this .slow (1 )
622-
623- it " SET" , () ->
624- start = Date .now ()
625- # not using forEach because it's magnitude 10 times slower than for
626- # and we are into a benchmark
627- for key in state .keys
628- should (localCache .set key, state .val , 0 ).be .ok ()
629- duration = Date .now () - start
630- if not process .env .SILENT_MODE ?
631- console .log " \t SET: #{ state .count } keys to: `#{ state .val } ` #{ duration} ms (#{ duration/ state .count } ms per item)"
632- else
633- BENCH[ " SET" ] = 1 / (( duration/ 1000 )/ state .count )
634- return
635-
636- it " GET" , () ->
637- # this benchmark is a bit useless because the equality check eats up
638- # around 3/4 of benchmark time
639- start = Date .now ()
640- for key in state .keys
641- state .n ++
642- state .val .should .eql localCache .get (key)
643- duration = Date .now () - start
644- if not process .env .SILENT_MODE ?
645- console .log " \t GET: #{ state .count } keys #{ duration} ms (#{ duration/ state .count } ms per item)"
646- else
647- BENCH[ " GET" ] = 1 / (( duration/ 1000 )/ state .count )
648- return
649-
650- it " check stats" , () ->
651- stats = localCache .getStats ()
652- keys = localCache .keys ()
653-
654- stats .keys .should .eql keys .length
655- state .count .should .eql keys .length
656- state .n .should .eql keys .length
657- return
658-
659- after () ->
660- if not process .env .SILENT_MODE ?
661- console .log " \t Benchmark stats:"
662- console .log stringify (localCache .getStats (), null , " \t " )
663- return
664- return
665- return
666-
667618
668619 describe " delete" , () ->
669620 this .timeout (0 )
670621
671622 before () ->
672623 # don't override state because we still need `state.keys`
673624 state .n = 0
674- state .startKeys = localCache .getStats ().keys
625+ return
626+
627+ before () ->
628+ state =
629+ n : 0
630+ count : 100000
631+ keys : []
632+ val : randomString 20
633+
634+ for [1 .. state .count ]
635+ key = randomString 7
636+ state .keys .push key
637+ localCache .set (key, state .val )
675638 return
676639
677640 it " delete all previously set keys" , () ->
@@ -680,6 +643,7 @@ describe "`#{pkg.name}@#{pkg.version}` on `node@#{process.version}`", () ->
680643 state .n ++
681644
682645 state .n .should .eql state .count
646+ localCache .getStats ().keys .should .eql 0
683647 return
684648
685649 it " delete keys again; should not delete anything" , () ->
@@ -831,23 +795,25 @@ describe "`#{pkg.name}@#{pkg.version}` on `node@#{process.version}`", () ->
831795 true .should .eql localCacheTTL .has state .key6
832796 return
833797
834- it " before it times out" , () ->
798+ it " before it times out" , (done ) ->
835799 setTimeout (() ->
836800 state .n ++
837801 res = localCacheTTL .has state .key6
838802 res .should .eql true
839803 state .val .should .eql localCacheTTL .get state .key6
804+ done ()
840805 return
841806 , 20 )
842807 return
843808
844- it " and after it timed out" , () ->
809+ it " and after it timed out" , (done ) ->
845810 setTimeout (() ->
846811 res = localCacheTTL .has state .key6
847812 res .should .eql false
848813
849814 state .n ++
850815 should (localCacheTTL .get state .key6 ).be .undefined ()
816+ done ()
851817 return
852818 , 800 )
853819 return
@@ -864,17 +830,18 @@ describe "`#{pkg.name}@#{pkg.version}` on `node@#{process.version}`", () ->
864830 state .val .should .eql localCache .get state .key1
865831 return
866832
867- it " before it times out" , () ->
833+ it " before it times out" , (done ) ->
868834 setTimeout (() ->
869835 state .n ++
870836 res = localCache .has state .key1
871837 res .should .eql true
872838 state .val .should .eql localCache .get state .key1
839+ done ()
873840 return
874841 , 20 )
875842 return
876843
877- it " and after it timed out" , () ->
844+ it " and after it timed out" , (done ) ->
878845 setTimeout (() ->
879846 res = localCache .has state .key1
880847 res .should .eql false
@@ -884,6 +851,7 @@ describe "`#{pkg.name}@#{pkg.version}` on `node@#{process.version}`", () ->
884851
885852 state .n ++
886853 should (localCache .get state .key1 ).be .undefined ()
854+ done ()
887855 return
888856 , 700 )
889857 return
@@ -898,22 +866,24 @@ describe "`#{pkg.name}@#{pkg.version}` on `node@#{process.version}`", () ->
898866 state .val .should .eql res
899867 return
900868
901- it " before it times out" , () ->
869+ it " before it times out" , (done ) ->
902870 setTimeout (() ->
903871 state .n ++
904872
905873 state .val .should .eql localCache .get state .key2
874+ done ()
906875 return
907876 , 20 )
908877 return
909878
910- it " and after it timed out, too" , () ->
879+ it " and after it timed out, too" , (done ) ->
911880 setTimeout (() ->
912881 ts = localCache .getTtl state .key2
913882 should .not .exist ts
914883
915884 state .n ++
916885 should (localCache .get state .key2 ).be .undefined ()
886+ done ()
917887 return
918888 , 500 )
919889 return
@@ -1146,32 +1116,30 @@ describe "`#{pkg.name}@#{pkg.version}` on `node@#{process.version}`", () ->
11461116 state .keyValueSet [0 ].key = true
11471117
11481118 (() -> localCacheMset .mset (state .keyValueSet )).should .throw ({
1149- name : " EKEYTYPE"
1150- message : " The key argument has to be of type `string` or `number`. Found: `boolean`"
1151- })
1119+ name : " EKEYTYPE"
1120+ message : " The key argument has to be of type `string` or `number`. Found: `boolean`"
1121+ })
11521122 return
11531123
11541124 it " mset - object key throw error" , () ->
11551125 localCacheMset .flushAll ()
11561126 state .keyValueSet [0 ].key = { a : 1 }
11571127
11581128 (() -> localCacheMset .mset (state .keyValueSet )).should .throw ({
1159- name : " EKEYTYPE"
1160- message : " The key argument has to be of type `string` or `number`. Found: `object`"
1161- })
1129+ name : " EKEYTYPE"
1130+ message : " The key argument has to be of type `string` or `number`. Found: `object`"
1131+ })
11621132 return
11631133
11641134 it " mset - ttl type error check" , () ->
11651135 localCacheMset .flushAll ()
11661136 state .keyValueSet [0 ].ttl = { a : 1 }
11671137
11681138 (() -> localCacheMset .mset (state .keyValueSet )).should .throw ({
1169- name : " ETTLTYPE"
1170- message : " The ttl argument has to be a number."
1171- })
1139+ name : " ETTLTYPE"
1140+ message : " The ttl argument has to be a number."
1141+ })
11721142 return
1173-
1174-
11751143
11761144 return
11771145
0 commit comments