Skip to content

Instantly share code, notes, and snippets.

@pulkit110
pulkit110 / mock_websocket_server.ex
Last active Aug 17, 2021
Supplementary Code for Testing WebSocket Clients in Elixir with a Mock Server
View mock_websocket_server.ex
defmodule Commerce.Orders.MockWebsocketServer do
use Plug.Router
plug(:match)
plug(:dispatch)
match _ do
send_resp(conn, 200, "Hello from plug")
end
View method_profiler.rb
require 'benchmark/ips'
require 'redis'
class MethodProfiler
def self.patch(klass, methods, name)
patches = methods.map do |method_name|
<<~RUBY
unless defined?(#{method_name}__mp_unpatched)
alias_method :#{method_name}__mp_unpatched, :#{method_name}
def #{method_name}(*args, &blk)
unless prof = Thread.current[:_method_profiler]