Don't add repository on worker events if it already exists

It's best to do that, because worker payload is usually outdated. If
there is no info on repo yet, it's worth to add it, but if it already
exists, we will most likely end up with inconsistent situation.
This commit is contained in:
Piotr Sarnacki 2012-10-27 03:11:15 +02:00
parent 94bff24f2c
commit 40ef7107f4
6 changed files with 94 additions and 9 deletions

View File

@ -77,14 +77,16 @@ Travis.Store = DS.Store.extend
_loadOne: (store, type, json) ->
root = type.singularName()
# we get other types of records only on build, it comes with repository
# attached. I don't want to use store.sideload here as it will not use merge,
# if we need sideload becasue we have side records with other events it needs to
# be revised
# we get other types of records only in a few situations and
# it's not always needed to update data, so I'm specyfing which
# things I want to update here:
if type == Travis.Build && (json.repository || json.repo)
@loadIncomplete(Travis.Repo, json.repository || json.repo)
else if type == Travis.Worker && json.worker.payload
if repo = (json.worker.payload.repo || json.worker.payload.repository)
# I use skipIfExists here, cause worker payload is usually outdated
# If there is no info on repo yet, it's worth to add it, but if it already
# exists, we will most likely end up with inconsistent situation
@loadIncomplete(Travis.Repo, repo, skipIfExists: true)
if job = json.worker.payload.job
@loadIncomplete(Travis.Job, job)
@ -102,7 +104,18 @@ Travis.Store = DS.Store.extend
if data = recordsData[clientId]
data.contains(key)
loadIncomplete: (type, hash) ->
loadIncomplete: (type, hash, options) ->
options ?= {}
id = hash.id
typeMap = @typeMapFor(type)
dataCache = typeMap.cidToHash
clientId = typeMap.idToCid[id]
if dataCache[clientId] && options.skipIfExists
return
result = @merge(type, hash)
if result && result.clientId

View File

@ -187,3 +187,33 @@ describe 'events', ->
row: 3
item: { name: 'ruby-3', state: 'ready' }
describe 'an event updating a worker', ->
beforeEach ->
app '/travis-ci/travis-core'
waitFor workersRendered
it 'does not update repository if it\'s already in store', ->
payload =
worker:
id: 1
host: 'worker.travis-ci.org'
name: 'ruby-2'
state: 'working'
payload:
repository:
id: 1
last_build_id: 999
last_build_number: '999'
Em.run ->
Travis.app.receive 'worker:updated', payload
waits(100)
runs ->
listsRepo
row: 2
item: { slug: 'travis-ci/travis-core', build: { number: 1, url: '/travis-ci/travis-core/builds/1', duration: '30 sec', finishedAt: '3 minutes ago' } }

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -8647,7 +8647,7 @@ return sinon;}.call(typeof window != 'undefined' && window || {}));
});
});
});
return describe('an event adding a worker', function() {
describe('an event adding a worker', function() {
beforeEach(function() {
app('');
return waitFor(workersRendered);
@ -8690,6 +8690,48 @@ return sinon;}.call(typeof window != 'undefined' && window || {}));
});
});
});
return describe('an event updating a worker', function() {
beforeEach(function() {
app('/travis-ci/travis-core');
return waitFor(workersRendered);
});
return it('does not update repository if it\'s already in store', function() {
var payload;
payload = {
worker: {
id: 1,
host: 'worker.travis-ci.org',
name: 'ruby-2',
state: 'working',
payload: {
repository: {
id: 1,
last_build_id: 999,
last_build_number: '999'
}
}
}
};
Em.run(function() {
return Travis.app.receive('worker:updated', payload);
});
waits(100);
return runs(function() {
return listsRepo({
row: 2,
item: {
slug: 'travis-ci/travis-core',
build: {
number: 1,
url: '/travis-ci/travis-core/builds/1',
duration: '30 sec',
finishedAt: '3 minutes ago'
}
}
});
});
});
});
});
}).call(this);

View File

@ -1 +1 @@
8c50af2e
0e66cadb