diff options
| -rw-r--r-- | src/weepinbell/http/client.clj | 37 | ||||
| -rw-r--r-- | test/weepinbell/microformats_test.clj | 1 | ||||
| -rw-r--r-- | test/weepinbell/storage_test.clj | 36 |
3 files changed, 53 insertions, 21 deletions
diff --git a/src/weepinbell/http/client.clj b/src/weepinbell/http/client.clj index f051d15..f854401 100644 --- a/src/weepinbell/http/client.clj +++ b/src/weepinbell/http/client.clj @@ -12,19 +12,15 @@ {:user-agent "WebmentionBot"
:timeout (* 20 1000)})
-(defn- wrap-response [response]
- (assoc response :content-length (or (get-in response [:headers "Content-Length"])
- (get-in response [:headers "content-length"]))))
-
(defn- wrap-promise [promised-response]
- (future (wrap-response @promised-response)))
+ (future @promised-response))
(defn post
"Sends POST request asynchronously. Returns a promise/future."
- ([url]
- (post url nil))
- ([url options]
- (post url options nil))
+ ;;([url]
+ ;; (post url nil))
+ ;;([url options]
+ ;; (post url options nil))
([url options callbacks]
(-> url
(hk/post (merge default-options options) callbacks)
@@ -32,8 +28,8 @@ (defn get
"Sends GET request asynchronously. Returns a promise/future."
- ([url]
- (get url nil))
+ ;;([url]
+ ;; (get url nil))
([url options]
(get url options nil))
([url options callbacks]
@@ -47,7 +43,7 @@ @(get url nil))
([url options]
@(get url options nil))
- ([url options callbacks]
+ #_([url options callbacks]
@(get url options callbacks)))
(defn head
@@ -61,14 +57,15 @@ (hk/head (merge default-options options) callbacks)
wrap-promise)))
-(defn head!
- "Sends HEAD request synchronously. Returns a response."
- ([url]
- @(head url nil))
- ([url options]
- @(head url options nil))
- ([url options callbacks]
- @(head url options callbacks)))
+;; Nothing referrences this function, commented for now
+;;(defn head!
+;; "Sends HEAD request synchronously. Returns a response."
+;; ([url]
+;; @(head url nil))
+;; ([url options]
+;; @(head url options nil))
+;; ([url options callbacks]
+;; @(head url options callbacks)))
(defn retryable? [error]
(let [retryables #{TimeoutException}]
diff --git a/test/weepinbell/microformats_test.clj b/test/weepinbell/microformats_test.clj index 16b09d8..5f17a5b 100644 --- a/test/weepinbell/microformats_test.clj +++ b/test/weepinbell/microformats_test.clj @@ -70,6 +70,7 @@ (testing "use-props get properties of a microformats item"
(->> testdata
(map #(is (= (->> % sr/use-items sr/find-h-entry (sr/use-prop :content))
+ (->> % sr/use-items sr/find-h-entry (sr/use-prop "content"))
(get-in % [:items first :properties :content first]))))
doall))
(testing "use-props works with out :properties key as well"
diff --git a/test/weepinbell/storage_test.clj b/test/weepinbell/storage_test.clj index 743a0cf..91b4ec0 100644 --- a/test/weepinbell/storage_test.clj +++ b/test/weepinbell/storage_test.clj @@ -115,11 +115,45 @@ (is (nil? ((:get storage) "source" nil)))
(is (nil? ((:get storage) nil nil))))
+(defn- test-friends [storage]
+ (let [id "123456789", mf {}
+ photo "https://source.net/photo.png"
+ data {:webmention {:id id
+ :source "https://source.net"
+ :target "https://target.net"
+ :modified (System/currentTimeMillis)}
+ :microformats mf
+ :extra {:proxied-photo photo}}]
+ ((:append storage) data)
+ (wait-til! ((:get storage) id))
+ (let [retrieved ((:get storage) id)]
+ (is (= photo (get-in retrieved [:extra :proxied-photo])))
+ (is (= mf (:microformats retrieved))))
+ ((:delete storage) id)
+ (wait-til! (not ((:get storage) id)))))
+
(deftest general-storage-test
(doseq [storage storages]
(doseq [testcase [[test-append-and-get "appending webmention"]
[test-append-and-get-list "appending and getting by domain"]
[test-update "updating webmentions"]
- [test-get-empty "making sure getting empty won't throw"]]]
+ [test-get-empty "making sure getting empty won't throw"]
+ [test-friends "friends of webmention (microformats, proxied-photo) can be stored correctly"]]]
(testing (last testcase)
((first testcase) storage)))))
+
+;; storage worker specifics
+
+(deftest storage-worker-test
+ (testing "Storage worker should keep working if some Exceptions occur"
+ (let [signal (promise)
+ [stop store] (-> edn-storage
+ (assoc :append (fn [_] (throw (Exception.))))
+ (assoc :delete (fn [& _] (deliver signal true)))
+ worker/start)]
+ ((:append store) {}) ;; this throws Exception inside worker
+ (Thread/sleep 50)
+ ((:delete store) {}) ;; if Exception was caught, this should gets done
+ (Thread/sleep 50)
+ (is signal)
+ (stop))))
|
