Skip to content

Commit

Permalink
Merge pull request #1 from ericwangqing/master
Browse files Browse the repository at this point in the history
m
  • Loading branch information
allenlongbaobao committed Sep 24, 2013
2 parents 5e89215 + 3ea1a46 commit 0741bf0
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 72 deletions.
4 changes: 0 additions & 4 deletions src/business/interesting-points-manager.ls
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,10 @@ create-interesting-point = !(location, interesting-point-data, callback)->
interesting-point = utils.clone interesting-point-data
interesting-point.within-location.lid = location._id
interesting-point.within-location.is-exist = true
# interesting-point.within-location.at-position = position-within-web-page: interesting-point.within-location.at-position
# delete interesting-point.within-location.at-position
(db) <-! database.get-db
(err, result) <-! db.at-plus['interesting-points'].insert interesting-point
callback summarize interesting-point



module.exports =
get-interesting-points-summaries-map: get-interesting-points-summaries-map
visit-uids-of-interesting-points-summaries-map: visit-uids-of-interesting-points-summaries-map
Expand Down
8 changes: 4 additions & 4 deletions src/business/locations-manager.ls
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ get-old-or-create-new-location = !(url-data, callback)->
else
current-time = new Date!
(db) <-! database.get-db
(err, location) <-! db.at-plus.locations.insert {
(err, locations) <-! db.at-plus.locations.insert {
type: 'web'
name: url-data.name
is-existing: true
Expand All @@ -56,10 +56,10 @@ get-old-or-create-new-location = !(url-data, callback)->
from: current-time
to: current-time
urls: [url-data.url]
retrieved-html: new-web-page.retrieved-html
server-retrieved-html: new-web-page.retrieved-html
}
place-web-page-snapshot new-web-page.snapshot, location._id
callback true, location
place-web-page-snapshot new-web-page.snapshot, locations[0]._id
callback true, locations[0]

place-web-page-snapshot = !(snapshot, lid)->
debug "*************** place-web-page-snapshot 尚未实现 ***************"
Expand Down
2 changes: 0 additions & 2 deletions src/business/messages-manager.ls
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ _ = require 'underscore'

get-recent-messages-map = !(ipids, callback)->
(db) <-! database.get-db
# cursor = db.at-plus.messages.find {ipid: "$in": ipids}
(err, messages) <-! db.at-plus.messages.find {ipid: "$in": ipids}
# .limit config.locations-channel.amount-of-recent-messages-in-interesting-points
.sort create-time: -1
.to-array
callback create-brief-recent-messages-map messages
Expand Down
5 changes: 3 additions & 2 deletions src/web-monitor/web-monitor.ls
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
require! ['./database','./testing-helper-channel'.get-testing-control]

find-location-for-url = !(url-data, callback)->
debug "*************** find-location-for-url 尚未实现,现在是个mock,通过testing-helper频道控制 ***************"
if not get-testing-control!.locations-manager.get-old-or-create-new-location.is-new
can-find = not get-testing-control!.locations-manager.get-old-or-create-new-location.is-new
debug "*************** find-location-for-url 尚未实现,现在是个mock,通过testing-helper频道控制。能找到?#{can-find} ***************"
if can-find
(db) <-! database.get-db
(err, location) <-! db.at-plus.locations.find-one
callback location, null
Expand Down
7 changes: 6 additions & 1 deletion test/helpers/test-create-a-new-ip-on-a-new-url-helper.ls
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ open-client-with-testing-helper = !(is-url-new-location, callback)->


open-two-clients = !(is-url-new-location, done, callback)->
(a-locations-channel, a-ip-channel, data) <-! open-client-with-testing-helper is-url-new-location = false
(a-locations-channel, a-ip-channel, data) <-! open-client-with-testing-helper is-url-new-location
(b-locations-channel, b-ip-channel, data) <-! open-client-without-testing-helper
done-waiter = new utils.All-done-waiter done
callback {locations: a-locations-channel, ip: a-ip-channel}, {locations: b-locations-channel, ip: b-ip-channel}, done-waiter.add-waiting-function
Expand All @@ -37,7 +37,12 @@ open-client = !(testing-helper-channel-config, callback)->
channels := cs
debug "客户端初始化完毕"

fake-figure-out-location-internality = (url, server-retrieved-html)->
# debug ' .... 真实的client会在这里将server-retrieved-html和自己打开的location(url)中的源码进行比较,确定是否一致。一致则是not internal,否则是internal ...'
true # 测试用true,激发服务器响应行为

module.exports =
open-client-without-testing-helper: open-client-without-testing-helper
open-client-with-testing-helper: open-client-with-testing-helper
open-two-clients: open-two-clients
fake-figure-out-location-internality: fake-figure-out-location-internality
93 changes: 62 additions & 31 deletions test/integrated/test-results-of-create-a-new-ip-on-a-new-url.ls
Original file line number Diff line number Diff line change
@@ -1,45 +1,22 @@
require! H: './test-create-a-new-ip-on-a-new-url-helper'
testing-data = total-locations-in-db = total-interestiong-points-in-db = null

describe '测试在新URL上创建新兴趣点时,Locations Channel与Interesting Points Channel的协同', !->
describe '创建兴趣点后,客户端接收到正确的数据,服务端正确保存了兴趣点', !->
testing-data = total-locations-in-db = total-interestiong-points-in-db = null
before-each !->
count-locaitons-in-db !(amount)-> total-locations-in-db := amount
count-interesting-points-in-db !(amount)-> total-interestiong-points-in-db := amount
testing-data := prepare-testing-data!

describe 'url为已有locatoin的alias时,消息内容正确,兴趣点正确保存', !->
can '创建者收到response-create-a-new-ip-on-a-new-url,之前在此页面的用户收到push-location-updated', !(done)->
(creator, observer, wait) <-! H.open-two-clients is-url-new-location = false, done
creator.ip.on 'response-create-a-new-ip-on-a-new-url', wait !(data)->
debug "创建者收到创建成功消息"
data.should.have.property 'lid'
data.should.have.property 'ipid'
data.result.should.eql 'success'

done-waiter = wait!
<-! should-db-not-include-any-new-location total-locations-in-db
<-! should-new-location-url-added-as-alias testing-data.request-create-a-new-ip-on-a-new-url
<-! should-db-include-a-new-interesting-point total-interestiong-points-in-db
<-! should-db-include-the-requested-new-ip testing-data.request-create-a-new-ip-on-a-new-url
done-waiter!

observer.locations.on 'push-location-updated', wait !(data)->
debug "观察者收到location更新消息"
data.type.should.eql 'new-ip-added'
data.should.have.property '_id'
data.added-interesting-point.should.have.property '_id'
data.added-interesting-point.created-by.should.have.property '_id'
(utils.chop-off-id data).should.eql (utils.chop-off-id testing-data.push-location-updated)

creator.locations.on 'push-location-updated', !(data)->
should.fail "创建者收到了'push-location-updated'"

observer.ip.on 'response-create-a-new-ip-on-a-new-url', !(data)->
should.fail "观察者收到了'response-create-a-new-ip-on-a-new-url'"

creator.ip.emit 'request-create-a-new-ip-on-a-new-url', testing-data.request-create-a-new-ip-on-a-new-url
should-creator-and-observer-recieved-correct-messages-AND-location-and-interesting-point-created \
is-url-new-location = false, done

describe 'url为新location时,消息内容正确,兴趣点正确保存', !->
can '创建者收到response-create-a-new-ip-on-a-new-url,之前在此页面的用户收到push-location-updated', !(done)->
should-creator-and-observer-recieved-correct-messages-AND-location-and-interesting-point-created \
is-url-new-location = true, done

before-each !(done)->
<-! server.start
Expand All @@ -59,20 +36,74 @@ prepare-testing-data = ->
request-create-a-new-ip-on-a-new-url: utils.load-fixture 'request-create-a-new-ip-on-a-new-url'
push-location-updated: utils.load-fixture 'push-location-updated'

should-creator-and-observer-recieved-correct-messages-AND-location-and-interesting-point-created = !(is-url-new-location, done)->
request = testing-data.request-create-a-new-ip-on-a-new-url
(creator, observer, wait) <-! H.open-two-clients is-url-new-location, done
creator.ip.on 'response-create-a-new-ip-on-a-new-url', wait !(data)->
debug "创建者收到创建成功消息"
data.should.have.property 'lid'
data.should.have.property 'ipid'
data.result.should.eql 'success'

done-waiter = wait!
<-! (if is-url-new-location then should-db-in-clude-a-new-location else should-db-not-include-any-new-location) total-locations-in-db
<-! (if is-url-new-location then should-db-in-clude-the-new-location else should-url-added-as-location-alias) request
<-! should-db-include-a-new-interesting-point total-interestiong-points-in-db
<-! should-db-include-the-requested-new-ip request
done-waiter!

if is-url-new-location
creator.locations.on 'ask-location-internality', wait !(data)->
debug "创建者收到查询internality消息"
data.should.have.property 'lid'
data.should.have.property 'url', request.within-location.url
data.should.have.property 'serverRetrievedHtml'

creator.locations.emit 'answer-location-internality',
{lid: data.lid, url: data.url, is-internal: H.fake-figure-out-location-internality!}

observer.locations.on 'push-location-updated', wait !(data)->
debug "观察者收到location更新消息"
data.type.should.eql 'new-ip-added'
data.should.have.property '_id'
data.added-interesting-point.should.have.property '_id'
data.added-interesting-point.created-by.should.have.property '_id'
(utils.chop-off-id data).should.eql (utils.chop-off-id testing-data.push-location-updated)

creator.locations.on 'push-location-updated', !(data)->
should.fail "创建者收到了'push-location-updated'"

observer.ip.on 'response-create-a-new-ip-on-a-new-url', !(data)->
should.fail "观察者收到了'response-create-a-new-ip-on-a-new-url'"

creator.ip.emit 'request-create-a-new-ip-on-a-new-url', request

count-locaitons-in-db = !(callback)->
count-amount-of-docs-in-a-collection 'locations', callback

count-interesting-points-in-db = !(callback)->
count-amount-of-docs-in-a-collection 'interesting-points', callback

should-db-in-clude-a-new-location = !(old-amount, callback)->
(locations) <-! query-collection 'locations', {}
locations.length.should.eql old-amount + 1
callback!

should-db-not-include-any-new-location = !(old-amount, callback)->
(locations) <-! query-collection 'locations', {}
locations.length.should.eql old-amount
callback!

should-new-location-url-added-as-alias = !(new-ip, callback)->
should-db-in-clude-the-new-location = !(new-ip, callback)->
(locations) <-! query-collection 'locations', {urls: new-ip.within-location.url}
locations.length.should.eql 1
locations[0].urls.length.should.eql 1 # 新location只有这一个url
callback!

should-url-added-as-location-alias = !(new-ip, callback)->
(locations) <-! query-collection 'locations', {urls: new-ip.within-location.url}
locations.length.should.eql 1
locations[0].urls.length.should.above 1 # 原有url,加上这个,超过1个
callback!


Expand Down
52 changes: 24 additions & 28 deletions test/integrated/test-workflow-of-create-a-new-ip-on-a-new-url.ls
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@ describe '创建的整个流程,有按照http://my.ss.sysu.edu.cn/wiki/pages/v
debug '''
************ 请注意,本测例需要人工观察,判断是否正确 **************
'''
# can '提交创建请求后,按照设计,服务端各模块执行了流程(url被解析为已有location的alias)', !(done)->
# H.open-client-with-testing-helper is-url-new-location = false, !(locations-channel, ip-channel, data)->
# debug-output-client-request-and-response-steps locations-channel, ip-channel, done
can '提交创建请求后,按照设计,服务端各模块执行了流程(url被解析为已有location的alias)', !(done)->
H.open-client-with-testing-helper is-url-new-location = false, !(locations-channel, ip-channel, data)->
debug-output-client-request-and-response-steps locations-channel, ip-channel, done

# can '提交创建请求后,按照设计,服务端各模块执行了流程(url被解析为新location的情况)', !(done)->
# H.open-client-with-testing-helper is-url-new-location = true, !(locations-channel, ip-channel, data)->
# debug-output-client-request-and-response-steps locations-channel, ip-channel, done
can '提交创建请求后,按照设计,服务端各模块执行了流程(url被解析为新location的情况)', !(done)->
H.open-client-with-testing-helper is-url-new-location = true, !(locations-channel, ip-channel, data)->
debug-output-client-request-and-response-steps locations-channel, ip-channel, done

describe '多人交互时,消息发送和接收正确', !->
request-data = null
before-each !-> request-data := utils.load-fixture 'request-create-a-new-ip-on-a-new-url'

describe 'url为已有locatoin的alias时,消息次序正确', !->
can '创建者收到response-create-a-new-ip-on-a-new-url,之前在此页面的用户收到push-location-updated', !(done)->
(creator, observer, wait) <-! H.open-two-clients is-url-new-location = false, done
Expand All @@ -22,24 +25,24 @@ describe '创建的整个流程,有按照http://my.ss.sysu.edu.cn/wiki/pages/v
observer.locations.on 'push-location-updated', wait !(data)-> debug "观察者收到location更新消息"
creator.locations.on 'push-location-updated', !(data)-> should.fail "创建者收到了'push-location-updated'"

creator.ip.emit 'request-create-a-new-ip-on-a-new-url', utils.load-fixture 'request-create-a-new-ip-on-a-new-url'
creator.ip.emit 'request-create-a-new-ip-on-a-new-url', request-data

# describe 'url为新的locatoin时,消息次序正确', !->
# can '创建者收到response-create-a-new-ip-on-a-new-url,之前在此页面的用户收到push-location-updated', !(done)->
# (creator, observer, wait) <-! H.open-two-clients is-url-new-location = true, done
# creator.ip.on 'response-create-a-new-ip-on-a-new-url', wait !(data)-> debug "创建者收到创建成功消息"
# observer.ip.on 'response-create-a-new-ip-on-a-new-url', !(data)-> should.fail "观察者收到了'response-create-a-new-ip-on-a-new-url'"
describe 'url为新的locatoin时,消息次序正确', !->
can '创建者收到response-create-a-new-ip-on-a-new-url,之前在此页面的用户收到push-location-updated', !(done)->
(creator, observer, wait) <-! H.open-two-clients is-url-new-location = true, done
creator.ip.on 'response-create-a-new-ip-on-a-new-url', wait !(data)-> debug "创建者收到创建成功消息"
observer.ip.on 'response-create-a-new-ip-on-a-new-url', !(data)-> should.fail "观察者收到了'response-create-a-new-ip-on-a-new-url'"

# observer.locations.on 'push-location-updated', wait !(data)-> debug "观察者收到location更新消息"
# creator.locations.on 'push-location-updated', !(data)-> should.fail "创建者收到了'push-location-updated'"
observer.locations.on 'push-location-updated', wait !(data)-> debug "观察者收到location更新消息"
creator.locations.on 'push-location-updated', !(data)-> should.fail "创建者收到了'push-location-updated'"

# creator.locations.on 'ask-location-internality', !(data)->
# debug "创建者收到了查询location internality消息"
# creator.locations.emit 'answer-location-internality', is-internal: fake-figure-out-location-internality data.url, data.server-retrieved-html
# observer.locations.on 'ask-location-internality', !(data)->
# should.fail "观察者收到了查询location internality消息"
creator.locations.on 'ask-location-internality', !(data)->
debug "创建者收到了查询location internality消息"
creator.locations.emit 'answer-location-internality', is-internal: H.fake-figure-out-location-internality data.url, data.server-retrieved-html
observer.locations.on 'ask-location-internality', !(data)->
should.fail "观察者收到了查询location internality消息"

# creator.ip.emit 'request-create-a-new-ip-on-a-new-url'
creator.ip.emit 'request-create-a-new-ip-on-a-new-url', request-data

before-each !(done)->
<-! server.start
Expand All @@ -58,7 +61,7 @@ debug-output-client-request-and-response-steps = !(locations-channel, ip-channel
locations-channel.on 'ask-location-internality', !(data)->
debug "@+ Client: ======== locations-channel in 'ask-location-internality' =========="
debug "@+ Client: ======== locations-channel emit 'answer-location-internality' =========="
locations-channel.emit 'answer-location-internality', is-internal: fake-figure-out-location-internality data.url, data.server-retrieved-html
locations-channel.emit 'answer-location-internality', is-internal: H.fake-figure-out-location-internality data.url, data.server-retrieved-html

locations-channel.on 'push-location-updated', !(data)->
debug "@+ Client: ======== in 'push-location-updated' ==========, channel id: ", locations-channel.socket.sessionid
Expand All @@ -69,10 +72,3 @@ debug-output-client-request-and-response-steps = !(locations-channel, ip-channel
set-timeout (!-> done!), 300 # 等待所有通信完成。
debug "@+ Client: ======== ip-channelemit 'request-create-a-new-ip-on-a-new-url' =========="
ip-channel.emit 'request-create-a-new-ip-on-a-new-url', utils.load-fixture 'request-create-a-new-ip-on-a-new-url'


fake-figure-out-location-internality = (url, server-retrieved-html)->
# debug ' .... 真实的client会在这里将server-retrieved-html和自己打开的location(url)中的源码进行比较,确定是否一致。一致则是not internal,否则是internal ...'
true # 测试用true,激发服务器响应行为


0 comments on commit 0741bf0

Please sign in to comment.