This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Remove Agent.spawn as that was only a playground for experimenting wi…

…th gRpc
  • Loading branch information...
bogdanbrato committed Jun 15, 2018
1 parent c0481af commit 271c4faaca3db9a6f36a191986a63a0d84f4758f
Showing with 0 additions and 74 deletions.
  1. +0 −18 agent/service.rb
  2. +0 −1 protos/agent.proto
  3. +0 −1 protos/agent_services_pb.rb
  4. +0 −54 spec/agent/service_spec.rb
View
@@ -8,24 +8,6 @@ module Agent
# A simple implementation of the agent service.
class Service < FastlaneCI::Proto::Agent::Service
include FastlaneCI::Agent::Logging
##
# this class is used to create a lazy enumerator
# that will yield back lines from the stdout/err of the process
# as well as the exit status when it is complete.
class ProcessOutputEnumerator
extend Forwardable
include Enumerable
def_delegators :@enumerator, :each, :next
def initialize(io, thread)
@enumerator = Enumerator.new do |yielder|
yielder.yield(io.gets) while thread.alive?
io.close
yielder.yield(EOT_CHAR, thread.value.exitstatus)
end
end
end
##
# returns a configured GRPC server ready to listen for connections.
View
@@ -11,7 +11,6 @@ syntax = "proto3";
package FastlaneCI.Proto;
service Agent {
rpc Spawn(Command) returns (stream InvocationResponse) {}
rpc RunFastlane(InvocationRequest) returns (stream InvocationResponse) {}
}

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -8,27 +8,6 @@
expect(FastlaneCI::Agent::Service.server).to be_instance_of(GRPC::RpcServer)
end
describe "#spawn" do
echo_message = "hello world"
let(:command) { instance_double("FastlaneCI::Agent::Command", env: {}, bin: "/bin/echo", parameters: [echo_message]) }
let(:call) { double("GRP Call") }
it "spawns a command with the environment and parameters" do
expect(Open3).to receive(:popen2e).and_call_original
service.spawn(command, call)
end
it "returns a ProcessEnumerator that contains the output of the command" do
responses = service.spawn(command, call)
expect(responses).to be_instance_of(Enumerator::Lazy)
expect(responses.peek.log.message).to start_with(echo_message)
responses.each do |response|
expect(response).to be_instance_of(FastlaneCI::Proto::InvocationResponse)
expect(response.log).to be_instance_of(FastlaneCI::Proto::Log)
end
end
end
describe "#run_fastlane" do
let(:call) { double("GRP Call") }
let(:command) { instance_double("FastlaneCI::Agent::Command", env: {}, bin: "/bin/echo", parameters: ["hello world"]) }
@@ -61,37 +40,4 @@
loop { responses.next }
end
end
describe FastlaneCI::Agent::Service::ProcessOutputEnumerator do
let(:io) { double("IO-like", gets: "this is a line of text\n") }
let(:thread_value) { double("thread value") }
let(:thread) { double("Thread", alive?: true, value: thread_value) }
let(:output_enumerator) { FastlaneCI::Agent::Service::ProcessOutputEnumerator.new(io, thread) }
it "will return lines of text from the file" do
expect(output_enumerator.next).to eq("this is a line of text\n")
end
it "enumerates lines from a file until the thread dies and returns its status" do
allow(thread).to receive(:alive?).and_return(false)
allow(thread_value).to receive(:exitstatus).and_return(0)
allow(io).to receive(:close)
expect { |block| output_enumerator.each(&block) }.to yield_with_args("\4", 0)
end
it "closes the file handle when the thread dies" do
allow(thread).to receive(:alive?).and_return(false)
allow(thread_value).to receive(:exitstatus).and_return(0)
expect(io).to receive(:close)
output_enumerator.next
end
it "can convert to a lazy Enumerator" do
expect(output_enumerator.lazy).to be_instance_of(Enumerator::Lazy)
end
end
end

0 comments on commit 271c4fa

Please sign in to comment.