Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7791381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:52:08+00:00 2026-06-01T21:52:08+00:00

I have a Sinatra app that runs inside of EventMachine. Currently, I am taking

  • 0

I have a Sinatra app that runs inside of EventMachine. Currently, I am taking a post request of JSON data, deferring storage, and returning a 200 OK status code. The deferred task simply pushes the data to a queue and increments a stats counter. The code is similar to:

class App < Sinatra::Base
  ...

  post '/' do
    json = request.body.read

    operation = lambda do
      push_to_queue(json)
      incr_incoming_stats
    end
    callback = lambda {}

    EM.defer(operation, callback)
  end

  ...
end

My question is, how do I test this functionality. If I use Rack::Test::Methods, then I have to put in something like sleep 1 to make sure the deferred task has completed before checking the queue and stats such that my test may look like:

it 'should push data to queue with valid request' do
  post('/', @json)
  sleep 1
  @redis.llen("#{@opts[:redis_prefix]}-queue").should > 0
end

Any help is appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T21:52:09+00:00Added an answer on June 1, 2026 at 9:52 pm

    The solution was pretty simple and once I realized it, I felt kind of silly. I created a test-helper that contained the following:

    module EM
      def self.defer(op, callback)
        callback.call(op.call)
      end
    end
    

    Then just include this into your test-files. This way the defer method will just run the operation and callback on the same thread.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this route in my Sinatra app: post ':type/new' do data = JSON.parse
So I have a Sinatra app that receives an XML via a HTTP POST
I have a Sinatra app that, boiled down, looks basically like this: class MyApp
I have a Sinatra app, that uses omniauth which constantantly gets this error attack
I have a Sinatra DataMapper app hitting a sqlite3 database that I am attempting
I have a .Net XML webservice that I need a simple Sinatra app to
In my sinatra app i have a form which is used to submit data
I have a Sinatra app that basically takes some input values and then finds
I have a Sinatra app that serves pages as read-only or editable depending on
I have a simple Sinatra app that I am playing with, and for some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.