restforce-db 4.0.3 → 4.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 222aeaddc4fb94b32a2b2eaacb3482762ede6c37
4
- data.tar.gz: 46a1f5236ee978d5753432cbbf46aac25c32970e
3
+ metadata.gz: c8a5c9eba12dc0b5c61dd46c6f72668d5b0e2328
4
+ data.tar.gz: a967c9fd3a4940ec403cb6386d7b1b510d6fc666
5
5
  SHA512:
6
- metadata.gz: 20120c3a574b33d70d4794a6ac868452661cbd247a069ba3f0e480a16cc1e299ac7bae17067d10bcb9a387009b0fef66b99a8e8796f99711733d378ba9f220e0
7
- data.tar.gz: 88161ce17126fe187092bbb8b006c4178eb946d30b7b7234084f1898f33b4e2638ca036875bb554c2b2e9bc4dc69d9a7587528d4d71da19698519efa7fdb3740
6
+ metadata.gz: 2ae6ffc5111235b6dbd23ab20e78076f6d47478bd706f8b2630b289a29eca449a23bad0d9bbc781fe65e304b5252d8498b1e805ca4d5c7ad579d1e37b7f5b86c
7
+ data.tar.gz: 1b4e5db790c4bc2d000519b57cc3321a1c34a5332c2858f693616692e548258c168aa076b5a7d3e0d729593477f998ef398145af9c66f8d7895652def7c33264
@@ -4,6 +4,8 @@ require "English"
4
4
  # forked process, and relaying its output to another block.
5
5
  class ForkedProcess
6
6
 
7
+ class UnsuccessfulExit < RuntimeError; end
8
+
7
9
  # Public: Define a callback which will be run in a forked process.
8
10
  #
9
11
  # Yields an IO object opened for writing when `run` is invoked.
@@ -39,7 +41,7 @@ class ForkedProcess
39
41
  @read_block.call(reader)
40
42
  Process.wait(pid)
41
43
 
42
- raise "Forked process did not exit successfully" unless $CHILD_STATUS.success?
44
+ raise UnsuccessfulExit unless $CHILD_STATUS.success?
43
45
  end
44
46
 
45
47
  end
@@ -59,6 +59,11 @@ module Restforce
59
59
 
60
60
  # Internal: Log a description and response time for a specific named task.
61
61
  #
62
+ # NOTE: AuthenticationErrors from Restforce's middleware seem to be linked
63
+ # to thread-safety issues, so we want to error out the entire processing
64
+ # loop in the event that we run into one of these. This is the reason for
65
+ # the fairly convoluted `rescue` chain below.
66
+ #
62
67
  # name - A String task name.
63
68
  # task_class - A Restforce::DB::Task subclass.
64
69
  # mapping - A Restforce::DB::Mapping.
@@ -70,6 +75,9 @@ module Restforce
70
75
  log format(" FINISHED #{name} after %.4f", runtime)
71
76
 
72
77
  true
78
+ rescue Restforce::AuthenticationError => e
79
+ error(e)
80
+ raise e
73
81
  rescue => e
74
82
  error(e)
75
83
  false
@@ -3,7 +3,7 @@ module Restforce
3
3
  # :nodoc:
4
4
  module DB
5
5
 
6
- VERSION = "4.0.3"
6
+ VERSION = "4.0.4"
7
7
 
8
8
  end
9
9
 
@@ -127,10 +127,11 @@ module Restforce
127
127
 
128
128
  begin
129
129
  forked.run
130
- rescue => e
130
+ rescue ForkedProcess::UnsuccessfulExit => e
131
131
  # NOTE: Due to thread-safety issues in any of a number of libraries
132
- # included in the host application (even ActiveSupport itself), our
133
- # forked processes may occasionally encounter LoadErrors.
132
+ # included in the host application (even in ActiveSupport itself),
133
+ # our forked processes may occasionally encounter various annoying
134
+ # and intermittent errors.
134
135
  #
135
136
  # Retrying here is our way of handling that. It's not great, but
136
137
  # it's the best we can do for now without sacrificing the benefits
@@ -1,5 +1,23 @@
1
1
  module Restforce
2
2
 
3
+ # :nodoc:
4
+ class Middleware::Authentication < Restforce::Middleware # rubocop:disable Style/ClassAndModuleChildren
5
+
6
+ # Internal: Get an error message for the passed response. Overrides the
7
+ # default behavior of the middleware to correctly handle broken responses
8
+ # from Faraday.
9
+ #
10
+ # Returns a String.
11
+ def error_message(response)
12
+ if response.status == 0
13
+ "Request was closed prematurely"
14
+ else
15
+ "#{response.body['error']}: #{response.body['error_description']}"
16
+ end
17
+ end
18
+
19
+ end
20
+
3
21
  # :nodoc:
4
22
  class SObject
5
23
 
@@ -0,0 +1,39 @@
1
+ require_relative "../test_helper"
2
+
3
+ describe ForkedProcess do
4
+
5
+ describe "running a forked process" do
6
+ let(:process) do
7
+ ForkedProcess.new.tap do |forked|
8
+ forked.write { |writer| writer.write("Hello!") }
9
+ end
10
+ end
11
+
12
+ describe "#run" do
13
+
14
+ it "synchronizes the `write` block's output into a `read` block" do
15
+ value = nil
16
+
17
+ process.read { |reader| value = reader.read }
18
+ process.run
19
+
20
+ expect(value).to_equal("Hello!")
21
+ end
22
+
23
+ describe "when the write block exits unsuccessfully due to an error" do
24
+ let(:process) do
25
+ ForkedProcess.new.tap do |forked|
26
+ forked.write { |_| raise "Whoops!" }
27
+ forked.read { |_| nil }
28
+ end
29
+ end
30
+
31
+ it "raises an UnsuccessfulExit exception" do
32
+ expect { silence_stream(STDERR) { process.run } }.to_raise(
33
+ ForkedProcess::UnsuccessfulExit,
34
+ )
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restforce-db
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.3
4
+ version: 4.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Horner
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-09-09 00:00:00.000000000 Z
11
+ date: 2015-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -337,6 +337,7 @@ files:
337
337
  - test/cassettes/Restforce_DB_Synchronizer/_run/given_a_Salesforce_record_with_no_associated_database_record/does_nothing_for_this_specific_mapping.yml
338
338
  - test/cassettes/Restforce_DB_Worker/a_race_condition_during_synchronization/does_not_change_the_user-entered_name_on_the_database_record.yml
339
339
  - test/cassettes/Restforce_DB_Worker/a_race_condition_during_synchronization/overrides_the_stale-but-more-recent_name_on_the_Salesforce.yml
340
+ - test/lib/forked_process_test.rb
340
341
  - test/lib/restforce/db/accumulator_test.rb
341
342
  - test/lib/restforce/db/adapter_test.rb
342
343
  - test/lib/restforce/db/association_cache_test.rb