File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed
Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ def self.save!(toggle_data)
66 Unleash . logger . debug "Will save toggles to disk now"
77
88 backup_file = Unleash . configuration . backup_file
9- backup_file_tmp = "#{ backup_file } .tmp"
9+ backup_file_tmp = "#{ backup_file } .tmp- #{ Process . pid } "
1010
1111 File . open ( backup_file_tmp , "w" ) do |file |
1212 file . write ( toggle_data )
Original file line number Diff line number Diff line change 6565 backup_file = Unleash . configuration . backup_file
6666 expect ( File . exist? ( backup_file ) ) . to eq ( true )
6767 end
68+
69+ # NOTE: this is a frequent issue with Puma (in clustered mode). See Unleash/unleash-ruby-sdk#108
70+ it 'does not log errors due to concurrent forked processes' do
71+ skip 'Fork not supported on current platform' unless Process . respond_to? ( :fork )
72+
73+ log_file = -> ( pid ) { File . join ( Dir . tmpdir , "#{ pid } .log" ) }
74+ pids = Array . new ( 10 ) do
75+ fork do
76+ Unleash . logger = Logger . new ( log_file . call ( Process . pid ) )
77+ expect ( Unleash . logger ) . not_to receive ( :error )
78+ described_class . new engine
79+ end
80+ end
81+
82+ pids . each do |pid |
83+ Process . wait ( pid )
84+ process_status = $? # rubocop:disable Style/SpecialGlobalVars
85+ error_log_file = log_file . call ( pid )
86+ expect ( File . exist? ( error_log_file ) )
87+
88+ error_msg = "Process #{ pid } failed with errors:\n #{ File . read ( error_log_file ) . lines [ 1 ..] . join } "
89+ expect ( process_status ) . to be_success , error_msg
90+ end
91+ end
6892 end
6993 end
7094
You can’t perform that action at this time.
0 commit comments