def run_fetcher(*args, &block)
      server = nil
      done = false
      last_exception = nil
      results = []
      EM.run do
        begin
          server = MockHTTPServer.new({:Logger => @logger}, &block)
          EM.defer do
            begin
              args.each do |source|
                results << source.call()
              end
            rescue Exception => e
              last_exception = e
            end
            done = true
          end
          timer = EM.add_periodic_timer(0.1) do
            if done
              timer.cancel
              timer = nil
              EM.next_tick do
                EM.stop
              end
            end
          end
          EM.add_timer(FETCH_TEST_TIMEOUT_SECS) { @logger.error("timeout"); raise "timeout" }
        rescue Exception => e
          last_exception = e
        end
      end

      # stop server, if any.
      (server.shutdown rescue nil) if server

      # reraise with full backtrace for debugging purposes. this assumes the
      # exception class accepts a single string on construction.
      if last_exception
        message = "#{last_exception.message}\n#{last_exception.backtrace.join("\n")}"
        if last_exception.class == ArgumentError
          raise ArgumentError, message
        else
          begin
            raise last_exception.class, message
          rescue ArgumentError
            # exception class does not support single string construction.
            message = "#{last_exception.class}: #{message}"
            raise message
          end
        end
      end

      return 1 == results.size ? results[0] : results
    end
def run_fetcher(*args, &block)
      server = nil
      done = false
      last_exception = nil
      results = []
      EM.run do
        begin
          server = MockHTTPServer.new({:Logger => @logger}, &block)
          EM.defer do
            begin
              args.each do |source|
                results << source.call()
              end
            rescue Exception => e
              last_exception = e
            end
            done = true
          end
          timer = EM.add_periodic_timer(0.1) do
            if done
              timer.cancel
              timer = nil
              EM.next_tick do
                EM.stop
              end
            end
          end
          EM.add_timer(FETCH_TEST_TIMEOUT_SECS) { @logger.error("timeout"); raise "timeout" }
        rescue Exception => e
          last_exception = e
        end
      end

      # stop server, if any.
      (server.shutdown rescue nil) if server

      # reraise with full backtrace for debugging purposes. this assumes the
      # exception class accepts a single string on construction.
      if last_exception
        message = "#{last_exception.message}\n#{last_exception.backtrace.join("\n")}"
        if last_exception.class == ArgumentError
          raise ArgumentError, message
        else
          begin
            raise last_exception.class, message
          rescue ArgumentError
            # exception class does not support single string construction.
            message = "#{last_exception.class}: #{message}"
            raise message
          end
        end
      end

      return 1 == results.size ? results[0] : results
    end
Runs the metadata provider after starting a server to respond to fetch
 requests.

 === Parameters
 metadata_provider(MetadataProvider):: metadata_provider to test

 metadata_formatter(MetadataFormatter):: metadata_formatter to test

 block(callback):: handler for server requests

 === Returns
 metadata(Hash):: flat metadata hash