1 | ger_tests = (ESM) ->
|
2 | actions = [ "view"]
|
3 | people = [1..10]
|
4 | things = [1..10]
|
5 |
|
6 | ns = global.default_namespace
|
7 | log = false
|
8 | random_created_at = ->
|
9 | moment().subtract(_.random(0, 120), 'minutes')
|
10 |
|
11 | compact= (ger) ->
|
12 |
|
13 | ger.compact_database(ns, {
|
14 | compact_database_person_action_limit: 10,
|
15 | compact_database_thing_action_limit: 10,
|
16 | actions: actions
|
17 | }).then( -> console.log 'finish compact' if log)
|
18 |
|
19 | add_events= (ger, n=100) ->
|
20 | events = []
|
21 | for y in [1..n]
|
22 | events.push {namespace: ns, person: _.sample(people), action: _.sample(actions), thing: _.sample(things),created_at: random_created_at(), expires_at: tomorrow}
|
23 | ger.events(events).then( -> console.log 'finish events' if log)
|
24 |
|
25 | recommend = (ger) ->
|
26 | ger.recommendations_for_person(ns, _.sample(people), actions: {buy:5, like:3, view:1}).then( -> console.log 'finish recs' if log)
|
27 |
|
28 | describe 'Async Method Tests', ->
|
29 |
|
30 |
|
31 | it "should not break when all functions are running at the same time", ->
|
32 | self = @
|
33 | console.log ""
|
34 | console.log ""
|
35 | console.log "####################################################"
|
36 | console.log "############## Async Tests ################"
|
37 | console.log "####################################################"
|
38 | console.log ""
|
39 | console.log ""
|
40 | time = 500
|
41 | @timeout(time + (20*1000))
|
42 | n = 5
|
43 | init_ger(ESM)
|
44 | .then((ger) ->
|
45 |
|
46 | promises = []
|
47 |
|
48 | for i in [1..n]
|
49 | promises.push compact(ger).then( -> add_events(ger)).then( -> recommend(ger))
|
50 | promises.push compact(ger).then( -> recommend(ger)).then( -> add_events(ger))
|
51 | promises.push add_events(ger).then( -> recommend(ger)).then( -> compact(ger))
|
52 | promises.push add_events(ger).then( -> compact(ger)).then( -> recommend(ger))
|
53 | promises.push recommend(ger).then( -> compact(ger)).then( -> add_events(ger))
|
54 | promises.push recommend(ger).then( -> add_events(ger)).then( -> compact(ger))
|
55 |
|
56 | bb.all(promises)
|
57 |
|
58 | )
|
59 | .then( ->
|
60 | console.log ""
|
61 | console.log ""
|
62 | console.log "####################################################"
|
63 | console.log "################ END OF Async Tests #########"
|
64 | console.log "####################################################"
|
65 | console.log ""
|
66 | console.log ""
|
67 | )
|
68 |
|
69 | module.exports = ger_tests; |
\ | No newline at end of file |