-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b261ca7
commit 116b044
Showing
4 changed files
with
123 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
require_relative "../spec_helper" | ||
|
||
describe Balladina::ChunkWriter, actor_system: :global do | ||
let(:target_dir) { Dir.tmpdir + "/balladina_tests" } | ||
|
||
before do | ||
@track = StubTrack.new | ||
@chunk_writer = Balladina::ChunkWriter.new(@track, target_dir) | ||
end | ||
|
||
after do | ||
@chunk_writer.terminate | ||
@track.terminate | ||
|
||
FileUtils.rm_rf target_dir | ||
end | ||
|
||
describe "writing chunks" do | ||
it "writes to disk and notifies the Track" do | ||
received_at = Time.now.to_i | ||
@chunk_writer.on_chunk received_at, "IMPORTANT AUDIO" | ||
expect(File.exist?(target_dir + "/#{received_at}.wav")).to be_true | ||
expect(@track.chunks).to have(1).item | ||
end | ||
end | ||
|
||
class StubTrack | ||
include Celluloid | ||
|
||
def initialize | ||
@chunks = [] | ||
end | ||
|
||
attr_reader :chunks | ||
|
||
def on_chunk(chunk_path) | ||
chunks << chunk_path | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
require_relative "../spec_helper" | ||
|
||
describe Balladina::TrackCoordinator, actor_system: :global do | ||
let(:socket) { double("socket") } | ||
let(:track) { double("track") } | ||
let(:board) { double("board") } | ||
|
||
before do | ||
@coordinator = Balladina::TrackCoordinator.new(socket, track, board, creates_socket_listeners: StubListener) | ||
end | ||
|
||
after do | ||
@coordinator.terminate | ||
end | ||
|
||
describe "processing messages from the control socket" do | ||
before do | ||
board.should_receive(:async).at_least(1).times.and_return board | ||
end | ||
|
||
it "tells the board to start recording" do | ||
board.should_receive(:start_recording) | ||
@coordinator.on_message "command" => "start_recording" | ||
end | ||
|
||
it "tells the board to stop recording" do | ||
board.should_receive(:stop_recording) | ||
@coordinator.on_message "command" => "stop_recording" | ||
end | ||
|
||
it "tells the board to promote another track to leader" do | ||
board.should_receive(:promote_leader).with "track-1" | ||
@coordinator.on_message "command" => "promote_leader", "data" => "track-1" | ||
end | ||
end | ||
|
||
describe "processing messages from the pub/sub channels" do | ||
it "notifies peers of who's ready or online" do | ||
socket.should_receive(:<<).twice | ||
@coordinator.notify_peers "peers_ready", ["track-1"] | ||
@coordinator.notify_peers "peers_online", ["track-1"] | ||
end | ||
|
||
it "controls its track's recording" do | ||
socket.should_receive(:<<).twice | ||
track.should_receive(:async).twice.and_return track | ||
track.should_receive(:start_recording) | ||
track.should_receive(:stop_recording) | ||
|
||
@coordinator.control_recording "start_recording" | ||
@coordinator.control_recording "stop_recording" | ||
end | ||
end | ||
|
||
describe "removing its Track from the board if it is terminated" do | ||
before do | ||
socket.should_receive(:<<).and_raise "hell" | ||
board.should_receive(:async).and_return board | ||
board.should_receive(:remove_track).with track | ||
end | ||
|
||
xit do | ||
@coordinator.control_recording "start_recording" | ||
end | ||
end | ||
|
||
class StubListener | ||
include Celluloid | ||
def initialize(*); end | ||
end | ||
end |