Skip to content
This repository has been archived by the owner on Sep 6, 2022. It is now read-only.

Commit

Permalink
Remove Agent.spawn as that was only a playground for experimenting wi…
Browse files Browse the repository at this point in the history
…th gRpc
  • Loading branch information
bogdanbrato committed Jun 15, 2018
1 parent c0481af commit 271c4fa
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 74 deletions.
18 changes: 0 additions & 18 deletions agent/service.rb
Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion protos/agent.proto
Expand Up @@ -11,7 +11,6 @@ syntax = "proto3";
package FastlaneCI.Proto;

service Agent {
rpc Spawn(Command) returns (stream InvocationResponse) {}
rpc RunFastlane(InvocationRequest) returns (stream InvocationResponse) {}
}

Expand Down
1 change: 0 additions & 1 deletion protos/agent_services_pb.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 0 additions & 54 deletions spec/agent/service_spec.rb
Expand Up @@ -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"]) }
Expand Down Expand Up @@ -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.