Operations are now Garbage Collected!
This commit is contained in:
@@ -14,7 +14,9 @@ Test = require "./TestSuite"
|
||||
|
||||
class JsonTest extends Test
|
||||
makeNewUser: (user, conn)->
|
||||
new Y.JsonFramework user, conn
|
||||
super new Y.JsonFramework user, conn
|
||||
|
||||
type: "JsonTest"
|
||||
|
||||
getRandomRoot: (user_num, root)->
|
||||
root ?= @users[user_num].getSharedObject()
|
||||
@@ -69,6 +71,7 @@ describe "JsonFramework", ->
|
||||
done()
|
||||
|
||||
it "can handle many engines, many operations, concurrently (random)", ->
|
||||
console.log "" # TODO
|
||||
@yTest.run()
|
||||
|
||||
it "has a change listener", ()->
|
||||
@@ -95,7 +98,7 @@ describe "JsonFramework", ->
|
||||
|
||||
|
||||
it "has a JsonTypeWrapper", ->
|
||||
y = this.yTest.getSomeUser().root_element
|
||||
y = this.yTest.getSomeUser().getSharedObject()
|
||||
y.val('x',"dtrn", 'immutable')
|
||||
y.val('set',{x:"x"}, 'immutable')
|
||||
w = y.value
|
||||
@@ -109,6 +112,7 @@ describe "JsonFramework", ->
|
||||
y.value.x = {q:4}
|
||||
expect(y.value.x.q).to.equal(4)
|
||||
|
||||
### TODO: Handle this test
|
||||
it "handles double-late-join", ->
|
||||
test = new JsonTest("double")
|
||||
test.run()
|
||||
@@ -120,6 +124,11 @@ describe "JsonFramework", ->
|
||||
u1.engine.applyOps ops2
|
||||
u2.engine.applyOps ops1
|
||||
expect(u2.value.name.val()).to.equal(u2.value.name.val())
|
||||
###
|
||||
|
||||
it "has a working test suite", ->
|
||||
@yTest.compareAll()
|
||||
|
||||
|
||||
it "can handle creaton of complex json", ->
|
||||
@yTest.getSomeUser().val('x', {'a':'b'})
|
||||
@@ -128,10 +137,10 @@ describe "JsonFramework", ->
|
||||
@yTest.getSomeUser().val('c', {'a':'c'})
|
||||
@yTest.getSomeUser().val('c', {'a':'b'})
|
||||
@yTest.compareAll()
|
||||
@yTest.getSomeUser().value.a.a.q.insertText(0,'AAA')
|
||||
q = @yTest.getSomeUser().value.a.a.q
|
||||
q.insertText(0,'A')
|
||||
@yTest.compareAll()
|
||||
expect(@yTest.getSomeUser().value.a.a.q.val()).to.equal("AAAdtrndtrtdrntdrnrtdnrtdnrtdnrtdnrdnrdt")
|
||||
|
||||
expect(@yTest.getSomeUser().value.a.a.q.val()).to.equal("Adtrndtrtdrntdrnrtdnrtdnrtdnrtdnrdnrdt")
|
||||
|
||||
it "handles immutables and primitive data types", ->
|
||||
@yTest.getSomeUser().val('string', "text", "immutable")
|
||||
@@ -144,18 +153,5 @@ describe "JsonFramework", ->
|
||||
expect(@yTest.getSomeUser().val('object').val('q')).to.equal "rr"
|
||||
expect(@yTest.getSomeUser().val('null') is null).to.be.ok
|
||||
|
||||
it "converges t1", ->
|
||||
op0 = {"type":"Delimiter","uid":{"creator":0,"op_number":0},"next":{"creator":0,"op_number":1}}
|
||||
op1 = {"type":"Delimiter","uid":{"creator":0,"op_number":1},"prev":{"creator":0,"op_number":0}}
|
||||
op2 = {"type":"WordType","uid":{"creator":0,"op_number":2},"beginning":{"creator":0,"op_number":0},"end":{"creator":0,"op_number":1}}
|
||||
op3 = {"type":"AddName","uid":{"creator":0,"op_number":3},"map_manager":{"creator":"_","op_number":"_"},"name":"name"}
|
||||
op4 = {"type":"Replaceable","content":{"creator":0,"op_number":2},"ReplaceManager":{"creator":"_","op_number":"___RM_name"},"prev":{"creator":"_","op_number":"___RM_name_beginning"},"next":{"creator":"_","op_number":"___RM_name_end"},"uid":{"creator":0,"op_number":4}}
|
||||
op5 = {"type":"TextInsert","content":"u","uid":{"creator":1,"op_number":2},"prev":{"creator":1,"op_number":0},"next":{"creator":1,"op_number":1}}
|
||||
op6 = {"type":"TextInsert","content":"w","uid":{"creator":2,"op_number":0},"prev":{"creator":0,"op_number":0},"next":{"creator":0,"op_number":1}}
|
||||
op7 = {"type":"TextInsert","content":"d","uid":{"creator":1,"op_number":0},"prev":{"creator":0,"op_number":0},"next":{"creator":2,"op_number":0}}
|
||||
op8 = {"type":"TextInsert","content":"a","uid":{"creator":1,"op_number":1},"prev":{"creator":1,"op_number":0},"next":{"creator":2,"op_number":0}}
|
||||
|
||||
ops = [op0, op1, op2, op3, op4, op5, op6, op7, op8]
|
||||
@test_user.engine.applyOps ops
|
||||
expect(@test_user.val('name').val()).to.equal("duaw")
|
||||
|
||||
|
||||
@@ -14,8 +14,8 @@ module.exports = class Test
|
||||
constructor: (@name_suffix = "")->
|
||||
@number_of_test_cases_multiplier = 1
|
||||
@repeat_this = 1 * @number_of_test_cases_multiplier
|
||||
@doSomething_amount = 200 * @number_of_test_cases_multiplier
|
||||
@number_of_engines = 7 + @number_of_test_cases_multiplier - 1
|
||||
@doSomething_amount = 800 * @number_of_test_cases_multiplier
|
||||
@number_of_engines = 5 + @number_of_test_cases_multiplier - 1
|
||||
|
||||
@time = 0
|
||||
@ops = 0
|
||||
@@ -29,12 +29,14 @@ module.exports = class Test
|
||||
@users = []
|
||||
@Connector = Connector_uninitialized @users
|
||||
for i in [0...@number_of_engines]
|
||||
@users.push @makeNewUser (i+@name_suffix), @Connector
|
||||
u = @makeNewUser (i+@name_suffix), @Connector
|
||||
@users.push u
|
||||
@users[0].val('name',"i")
|
||||
@flushAll()
|
||||
|
||||
makeNewUser: (user_id, Connector)->
|
||||
throw new Error "overwrite me!"
|
||||
makeNewUser: (user)->
|
||||
user.HB.setManualGarbageCollect()
|
||||
user
|
||||
|
||||
getSomeUser: ()->
|
||||
i = _.random 0, (@users.length-1)
|
||||
@@ -43,6 +45,7 @@ module.exports = class Test
|
||||
getRandomText: (chars, min_length = 0)->
|
||||
chars ?= "abcdefghijklmnopqrstuvwxyz"
|
||||
length = _.random min_length, 10
|
||||
#length = 1
|
||||
nextchar = chars[(_.random 0, (chars.length-1))]
|
||||
text = ""
|
||||
_(length).times ()-> text += nextchar
|
||||
@@ -74,11 +77,6 @@ module.exports = class Test
|
||||
y.insertText pos, @getRandomText()
|
||||
null
|
||||
types: [types.WordType]
|
||||
,
|
||||
f : (y)=> # REPLACE TEXT
|
||||
y.replaceText @getRandomText()
|
||||
null
|
||||
types: [types.WordType]
|
||||
,
|
||||
f : (y)-> # DELETE TEXT
|
||||
if y.val().length > 0
|
||||
@@ -87,8 +85,12 @@ module.exports = class Test
|
||||
ops1 = y.deleteText pos, length
|
||||
undefined
|
||||
types : [types.WordType]
|
||||
,
|
||||
f : (y)=> # REPLACE TEXT
|
||||
y.replaceText @getRandomText()
|
||||
null
|
||||
types: [types.WordType]
|
||||
]
|
||||
|
||||
getRandomRoot: (user_num)->
|
||||
throw new Error "overwrite me!"
|
||||
|
||||
@@ -116,8 +118,10 @@ module.exports = class Test
|
||||
choice = _.random (choices.length-1)
|
||||
choices[choice](user_num)
|
||||
|
||||
flushAll: ()->
|
||||
if @users.length <= 1
|
||||
flushAll: (final)->
|
||||
# TODO:!!
|
||||
final = false
|
||||
if @users.length <= 1 or not final
|
||||
for user,user_number in @users
|
||||
user.getConnector().flushAll()
|
||||
else
|
||||
@@ -129,7 +133,7 @@ module.exports = class Test
|
||||
|
||||
|
||||
compareAll: (test_number)->
|
||||
@flushAll()
|
||||
@flushAll(true)
|
||||
|
||||
@time += (new Date()).getTime() - @time_now
|
||||
|
||||
@@ -139,8 +143,8 @@ module.exports = class Test
|
||||
@ops += number_of_created_operations*@users.length
|
||||
|
||||
ops_per_msek = Math.floor(@ops/@time)
|
||||
if test_number? and @debug
|
||||
console.log "#{test_number}/#{@repeat_this}: Every collaborator (#{@users.length}) applied #{number_of_created_operations} ops in a different order." + " Over all we consumed #{@ops} operations in #{@time/1000} seconds (#{ops_per_msek} ops/msek)."
|
||||
if test_number? # and @debug
|
||||
console.log "#{test_number}/#{@repeat_this}: #{number_of_created_operations} were created and applied on (#{@users.length}) users ops in a different order." + " Over all we consumed #{@ops} operations in #{@time/1000} seconds (#{ops_per_msek} ops/msek)."
|
||||
|
||||
for i in [0...(@users.length-1)]
|
||||
if @debug
|
||||
@@ -179,7 +183,12 @@ module.exports = class Test
|
||||
console.log ''
|
||||
for times in [1..@repeat_this]
|
||||
@time_now = (new Date).getTime()
|
||||
for i in [1..@doSomething_amount]
|
||||
for i in [1..Math.floor(@doSomething_amount/2)]
|
||||
@doSomething()
|
||||
@flushAll(false)
|
||||
for u in @users
|
||||
u.HB.emptyGarbage()
|
||||
for i in [1..Math.floor(@doSomething_amount/2)]
|
||||
@doSomething()
|
||||
|
||||
@compareAll(times)
|
||||
@@ -188,8 +197,13 @@ module.exports = class Test
|
||||
@reinitialize()
|
||||
|
||||
testHBencoding: ()->
|
||||
@users[@users.length] = @makeNewUser 'testuser', (Connector_uninitialized [])
|
||||
# in case of JsonFramework, every user will create its JSON first! therefore, the testusers id must be small than all the others (see InsertType)
|
||||
@users[@users.length] = @makeNewUser (-1), (Connector_uninitialized [])
|
||||
@users[@users.length-1].engine.applyOps @users[0].HB._encode()
|
||||
|
||||
#if @getContent(@users.length-1) isnt @getContent(0)
|
||||
# console.log "testHBencoding:"
|
||||
# console.log "Unprocessed ops first: #{@users[0].engine.unprocessed_ops.length}"
|
||||
# console.log "Unprocessed ops last: #{@users[@users.length-1].engine.unprocessed_ops.length}"
|
||||
expect(@getContent(@users.length-1)).to.deep.equal(@getContent(0))
|
||||
|
||||
|
||||
@@ -11,10 +11,12 @@ Y = require "../lib/index"
|
||||
Connector_uninitialized = require "../lib/Connectors/TestConnector"
|
||||
|
||||
Test = require "./TestSuite"
|
||||
|
||||
class TextTest extends Test
|
||||
|
||||
type: "TextTest"
|
||||
|
||||
makeNewUser: (user, conn)->
|
||||
new Y.TextFramework user, conn
|
||||
super new Y.TextFramework user, conn
|
||||
|
||||
getRandomRoot: (user_num)->
|
||||
@users[user_num].getSharedObject()
|
||||
@@ -22,7 +24,6 @@ class TextTest extends Test
|
||||
getContent: (user_num)->
|
||||
@users[user_num].val()
|
||||
|
||||
|
||||
describe "TextFramework", ->
|
||||
beforeEach (done)->
|
||||
@timeout 50000
|
||||
@@ -32,5 +33,14 @@ describe "TextFramework", ->
|
||||
@test_user = @yTest.makeNewUser 0, (Connector_uninitialized [])
|
||||
done()
|
||||
|
||||
it "simple multi-char insert", ->
|
||||
u = @yTest.getSomeUser()
|
||||
u.insertText 0, "abc"
|
||||
@yTest.compareAll()
|
||||
expect(u.val()).to.equal("abc")
|
||||
|
||||
it "can handle many engines, many operations, concurrently (random)", ->
|
||||
@yTest.run()
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user