Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jmrunge/tests #141

Open
wants to merge 93 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
5a83cad
add back mosto status test
Lacrymology Sep 11, 2013
a90da87
logging
Lacrymology Sep 11, 2013
aa691d1
whitespace
Lacrymology Sep 11, 2013
a35e36c
return models tests
Lacrymology Sep 11, 2013
8244ae2
getWindow doesn't exist anymore
Lacrymology Sep 11, 2013
21e9f62
fix 'should responde to create messages' test for new format
Lacrymology Oct 7, 2013
a1cef11
use new commands
Lacrymology Oct 7, 2013
8ce59db
fix blank clip name
Lacrymology Oct 7, 2013
20f7cf3
add functional test back
Lacrymology Oct 7, 2013
868fdd4
require only the... required.. driver
Lacrymology Oct 9, 2013
49d8127
fix helper functions for new models
Lacrymology Oct 9, 2013
bd1e4b3
there's no more 'promisedCommand' methods
Lacrymology Oct 9, 2013
8d734d8
the telltale string changed
Lacrymology Oct 9, 2013
34e11fa
call done(), make sure we pass no arguments
Lacrymology Oct 9, 2013
e69ea19
is_synced receives the time
Lacrymology Oct 9, 2013
ae457f9
better logging on mongo driver
Lacrymology Oct 9, 2013
55a52bb
listen on status change on pub/sub instead of on mosto events
Lacrymology Oct 9, 2013
a379797
remove dead code
Lacrymology Oct 9, 2013
c39096c
make sure to use safe:true in inserts
Lacrymology Oct 11, 2013
d9b45a8
skip 'start with playlists'
Lacrymology Oct 11, 2013
7c4ac09
Took out semaphore from api/Melted
jmrunge Nov 28, 2013
7f30e5f
Modified mosto core to stop using melted semaphore
jmrunge Nov 28, 2013
6f15d7e
Added test helper with semaphore and init+finish code for each test
jmrunge Nov 28, 2013
5a1ce31
Added init and finish calls to helper to functional test
jmrunge Nov 28, 2013
26a46b3
Replaced melted take with helper init and finish calls in heartbeats …
jmrunge Nov 28, 2013
471a597
Replaced melted take with init and finish calls to helper in models test
jmrunge Nov 28, 2013
2a106eb
Replaced melted take with init and finish calls to helper in status test
jmrunge Nov 28, 2013
6708361
Replaced melted take with helper init and finish calls in mvcp driver…
jmrunge Nov 28, 2013
f53c36f
Replaced melted take with init and finish calls to helper in mongo test
jmrunge Nov 28, 2013
db52a33
Added pubsub the option to receive custom config to set up db
jmrunge Nov 28, 2013
3bd3c4e
Removed unused dependency
jmrunge Nov 28, 2013
1872042
Added logging
jmrunge Nov 28, 2013
23f7424
Added Models the option to send arguments to MeltedCollection.set via…
jmrunge Nov 28, 2013
81be75e
Added mosto core the option to receive custom db config and pass it t…
jmrunge Nov 28, 2013
5b02da4
Logging
jmrunge Nov 28, 2013
c79e609
Incremented finish timeout in mosto core
jmrunge Nov 28, 2013
0518d23
Added logger to melted-node in functional test so it starts respectin…
jmrunge Nov 28, 2013
7f45f61
Set mongo config to mosto so it sends it to mongo driver and pubsub
jmrunge Nov 28, 2013
24bcc01
Removed skip from functional test start with playlists
jmrunge Nov 28, 2013
6aac1f7
Wait for BLANK file in listener before continuing with the test
jmrunge Nov 28, 2013
7edbfa5
Added helper function to get medias as JSON
jmrunge Nov 28, 2013
66f8168
Changed the way of creating pieces (using JSON instead of Media.Model…
jmrunge Nov 28, 2013
4d176dc
Added LOG_LEVEL to npm test (used by travis) because it claims log be…
jmrunge Nov 28, 2013
3606541
Incremented timout on mosto finish due travis errors
jmrunge Nov 28, 2013
45282be
Unsuscribe from events after receive the one needed
jmrunge Nov 28, 2013
3a20c47
Removed node 0.8 from travis config
jmrunge Dec 2, 2013
65816d3
add back mosto status test
Lacrymology Sep 11, 2013
34392da
logging
Lacrymology Sep 11, 2013
1033d94
whitespace
Lacrymology Sep 11, 2013
a9513ba
return models tests
Lacrymology Sep 11, 2013
57a0ffd
getWindow doesn't exist anymore
Lacrymology Sep 11, 2013
8f8b5e2
fix 'should responde to create messages' test for new format
Lacrymology Oct 7, 2013
963dfdb
use new commands
Lacrymology Oct 7, 2013
d927cc6
fix blank clip name
Lacrymology Oct 7, 2013
2c92091
add functional test back
Lacrymology Oct 7, 2013
f06ed20
require only the... required.. driver
Lacrymology Oct 9, 2013
bce61c2
fix helper functions for new models
Lacrymology Oct 9, 2013
6602e51
there's no more 'promisedCommand' methods
Lacrymology Oct 9, 2013
6d67320
the telltale string changed
Lacrymology Oct 9, 2013
60ef578
call done(), make sure we pass no arguments
Lacrymology Oct 9, 2013
0e06264
is_synced receives the time
Lacrymology Oct 9, 2013
c821b30
better logging on mongo driver
Lacrymology Oct 9, 2013
345fbb8
listen on status change on pub/sub instead of on mosto events
Lacrymology Oct 9, 2013
01162ef
remove dead code
Lacrymology Oct 9, 2013
1150e1e
make sure to use safe:true in inserts
Lacrymology Oct 11, 2013
a9f6b1c
skip 'start with playlists'
Lacrymology Oct 11, 2013
39e9de1
Took out semaphore from api/Melted
jmrunge Nov 28, 2013
e830f57
Modified mosto core to stop using melted semaphore
jmrunge Nov 28, 2013
4311041
Added test helper with semaphore and init+finish code for each test
jmrunge Nov 28, 2013
3ba0000
Added init and finish calls to helper to functional test
jmrunge Nov 28, 2013
780de35
Replaced melted take with helper init and finish calls in heartbeats …
jmrunge Nov 28, 2013
8038ef6
Replaced melted take with init and finish calls to helper in models test
jmrunge Nov 28, 2013
0114426
Replaced melted take with init and finish calls to helper in status test
jmrunge Nov 28, 2013
e849fc2
Replaced melted take with helper init and finish calls in mvcp driver…
jmrunge Nov 28, 2013
7709819
Replaced melted take with init and finish calls to helper in mongo test
jmrunge Nov 28, 2013
1cd837e
Added pubsub the option to receive custom config to set up db
jmrunge Nov 28, 2013
2c88034
Removed unused dependency
jmrunge Nov 28, 2013
170c741
Added logging
jmrunge Nov 28, 2013
2e3698e
Added Models the option to send arguments to MeltedCollection.set via…
jmrunge Nov 28, 2013
e6f2ca0
Added mosto core the option to receive custom db config and pass it t…
jmrunge Nov 28, 2013
fde836d
Logging
jmrunge Nov 28, 2013
8507fb0
Incremented finish timeout in mosto core
jmrunge Nov 28, 2013
733866b
Added logger to melted-node in functional test so it starts respectin…
jmrunge Nov 28, 2013
6efb4c3
Set mongo config to mosto so it sends it to mongo driver and pubsub
jmrunge Nov 28, 2013
cc06dc6
Removed skip from functional test start with playlists
jmrunge Nov 28, 2013
46a7043
Wait for BLANK file in listener before continuing with the test
jmrunge Nov 28, 2013
e6ed1fa
Added helper function to get medias as JSON
jmrunge Nov 28, 2013
dd4a849
Changed the way of creating pieces (using JSON instead of Media.Model…
jmrunge Nov 28, 2013
2bd4a6b
Added LOG_LEVEL to npm test (used by travis) because it claims log be…
jmrunge Nov 28, 2013
c1279e5
Incremented timout on mosto finish due travis errors
jmrunge Nov 28, 2013
7a83fbc
Unsuscribe from events after receive the one needed
jmrunge Nov 28, 2013
4263243
Merge branch 'jmrunge/tests' of https://github.com/inaes-tic/mbc-most…
jmrunge Dec 2, 2013
5ab5457
Incremented timeout to check for Melted because it was to tight for n…
jmrunge Dec 2, 2013
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
language: node_js
node_js:
- "0.10"
- "0.8"
services:
- mongodb
- redis
Expand Down
19 changes: 1 addition & 18 deletions api/Melted.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
var spawn = require('child_process').spawn;
var exec = require('child_process').exec;
var net = require('net');
var semaphore = require('semaphore')(1);
var mbc = require('mbc-common');
var conf = mbc.config.Mosto.Melted;
var melted_bin_path = conf.root + '/melted/BUILD/bin/melted';
Expand Down Expand Up @@ -176,6 +175,7 @@ exports.push = function(conn, commands, command_callback, close_callback) {
var s = 0;
conn.on('connect', function() {
conn.on('data', function(data) {
logger.debug('[push] got data: "%s"', data);
if (command_callback) command_callback(data);
if (s < commands.length && data.indexOf("\n") > -1) {
conn.write(commands[s]+"\n");
Expand Down Expand Up @@ -208,20 +208,3 @@ exports.setup = function(root, output, callback) {
})
};

/**
* take
*
* Take melted and not leave execution to other melted taked.
*
* @callback: callback function to process while take melted.
*
*/
exports.take = semaphore.take;

/**
* leave
*
* Leave execution to other melted taked.
*
*/
exports.leave = semaphore.leave;
5 changes: 3 additions & 2 deletions drivers/playlists/mongo-driver.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
var mbc = require('mbc-common')
, config = mbc.config.Mosto.Mongo
, mubsub = require("mubsub")
, moment = require("moment")
, async = require('async')
Expand Down Expand Up @@ -28,6 +27,7 @@ util.inherits (mongo_driver, events.EventEmitter);

mongo_driver.prototype.start = function() {
var self = this;
logger.info("Opening db connection", this.conf);
var db = mbc.db(this.conf && this.conf.db);
self.channel = mbc.pubsub();

Expand Down Expand Up @@ -144,8 +144,9 @@ mongo_driver.prototype.createPlaylist = function(sched, callback) {
}
logger.debug("LIST:" + list._id);

logger.info("Processing list:", {"id": list && list._id, "clips": list && list.pieces.length});
logger.info("Processing list:", {"id": list && list._id, "clips": list && list.pieces});
self.pieces.findItems({_id:{"$in": list.pieces}}, function(err, pieces) {
logger.info('found', (pieces && pieces.length) || 0, 'pieces');
pieces = _.chain(pieces).map(function(block){
block._id = (block._id.toHexString && block._id.toHexString()) || block._id;
return block;
Expand Down
11 changes: 7 additions & 4 deletions drivers/playlists/playlists-driver.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
var json_driver = require("./json-driver"),
mongo_driver = require("./mongo-driver"),
mbc = require("mbc-common"),
logger = mbc.logger().addLogger('PLAYLISTS-DRIVER');
var mbc = require("mbc-common"),
logger = mbc.logger().addLogger('PLAYLISTS-DRIVER'),

exports = module.exports = function(type, config) {
logger.info("Creating playlists driver for type [" + type + "]");

if (type === 'json') {
var json_driver = require("./json-driver");
return new json_driver(config);
} else if (type === 'mongo') {
var mongo_driver = require("./mongo-driver");
return new mongo_driver(config);
} else if (type === 'test') {
var test_driver = require("./test-driver");
return new test_driver(config);
}

/******************************************************************
Expand Down
8 changes: 4 additions & 4 deletions drivers/status/pubsub.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ function MostoMessage(value, description, message) {
this.message = message;
}

function CaspaDriver() {
function CaspaDriver(conf) {
events.EventEmitter.call(this);
var self = this;
this.status = _.clone(defaults);
this.db = mbc.db();
this.db = mbc.db(conf && conf.db);
this.publisher = mbc.pubsub();
}
util.inherits(CaspaDriver, events.EventEmitter);
Expand Down Expand Up @@ -194,8 +194,8 @@ CaspaDriver.prototype.dropMessage = function(message) {
this.publisher.publish("mostoMessage.delete", { model: message });
};

exports = module.exports = function() {
var driver = new CaspaDriver();
exports = module.exports = function(conf) {
var driver = new CaspaDriver(conf);
driver.setupAll();

return driver;
Expand Down
4 changes: 2 additions & 2 deletions models/Mosto.js
Original file line number Diff line number Diff line change
Expand Up @@ -553,12 +553,12 @@ Mosto.LoadedPlaylists = Backbone.Model.extend({
this.get('melted_medias').on('all', bubbleEvents(this, 'melted_medias'));
},

save: function() {
save: function(options) {
// set fires add, remove, change and sort
var mm = this.get('melted_medias');
var pl = this.get('playlists');
mm.write.take(function() {
mm.set(pl.getMedias());
mm.set(pl.getMedias(), options);
});
},

Expand Down
43 changes: 28 additions & 15 deletions mosto.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ var fs = require('fs')
, utils = require('./utils')
, mbc = require('mbc-common')
, config = mbc.config.Mosto.General
, mongoConfig = mbc.config.Mosto.Mongo
, _ = require('underscore')
, heartbeats = require('./heartbeats')
, models = require('./models/Mosto')
, logger = mbc.logger().addLogger('CORE')
;
//TODO: Chequear window, se esta construyendo de formas distintas
//INCLUSO EN EL DRIVER MISMO SE USA DE FORMAS DISTINTAS!!!
function mosto(customConfig) {
function mosto(customConfig, customMongoConfig) {

/** CONFIGURATION */
this.config = customConfig || config;
this.mongoConfig = customMongoConfig || mongoConfig;
this.server = undefined;
this.pl_driver = undefined;
this.status_driver = undefined;
Expand Down Expand Up @@ -224,8 +226,9 @@ mosto.prototype.init = function(melted, callback) {
* linkear heartbeat con status driver
*/
function startall() {
self.pl_driver = new playlists_driver(self.config.playlist_server);
self.status_driver = new status_driver();
logger.info("Starting modules...");
self.pl_driver = new playlists_driver(self.config.playlist_server, self.mongoConfig);
self.status_driver = new status_driver(self.mongoConfig);
self.playlists = models.Playlists();
self.heartbeats = new heartbeats();

Expand All @@ -243,23 +246,24 @@ mosto.prototype.init = function(melted, callback) {
self.checkMelted(startall);
};

if (melted !== undefined) {
if (melted !== undefined)
Melted = melted;
check_and_start();
}
else
Melted.take(check_and_start);

check_and_start();

};

mosto.prototype.scheduleMeltedCheck = function() {
this.meltedInterval = setTimeout(this.checkMelted.bind(this, this.scheduleMeltedCheck.bind(this), true), 100);
this.meltedInterval = setTimeout(this.checkMelted.bind(this, this.scheduleMeltedCheck.bind(this), true), 500);
logger.debug("Melted Timeout id:", this.meltedInterval);
};

mosto.prototype.checkMelted = function(callback, forceLoad) {
logger.debug("Checking melted...");
var self = this;
Melted.is_running(function(running) {
if (!running) {
logger.error("Melted was not running!");
Melted.start(function(pid) {
Melted.setup(undefined, undefined, function(result) {
if (forceLoad)
Expand All @@ -278,24 +282,33 @@ mosto.prototype.checkMelted = function(callback, forceLoad) {
mosto.prototype.finish = function(callback) {
var self = this;
logger.info("mbc-mosto: [INFO] Finish mbc-mosto... ");
if (self.restartMelted)
if (self.restartMelted) {
logger.debug("Clearing Melted Timeout id:", self.meltedInterval);
clearTimeout(self.meltedInterval);
}
this.stopDriver();
this.playlists.get("melted_medias").write.take(function() {
self.playlists.get("melted_medias").stopMvcpServer().fin(self.stopHeartbeats).fin(function() {
logger.debug("[finish] stop melted_medias mvcp server");
self.playlists.get("melted_medias").stopMvcpServer().fin(function() {
logger.debug("[finish] stop heartbeats");
return self.stopHeartbeats();
}).fin(function() {
logger.debug("[finish] leave melted_medias write lock")
self.playlists.get("melted_medias").write.leave();
logger.debug("[finish] stop Melted");
Melted.stop(function(pid) {
logger.debug("[finish] melted stopped");
setTimeout( function() {
Melted.leave();
logger.debug("[finish] calling callback");
if (callback) callback();
}, 1000 );
}, 7000 );
});
});
});
};

exports = module.exports = function(customConfig) {
var mosto_server = new mosto(customConfig);
exports = module.exports = function(customConfig, customMongoConfig) {
var mosto_server = new mosto(customConfig, customMongoConfig);
return mosto_server;
};
/*
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"author": "Juan Martin Runge <jmrunge@gmail.com>",
"contributors": [ "Niv Sardi <xaiki@inaes.gob.ar>", "hatcsh"],
"scripts": {
"test": "make coverage"
"test": "make LOG_LEVEL=info coverage"
},
"main": "mosto",
"repository": {
Expand Down
Loading