File tree Expand file tree Collapse file tree 4 files changed +37
-6
lines changed
tests/lib/Files/Storage/Wrapper Expand file tree Collapse file tree 4 files changed +37
-6
lines changed Original file line number Diff line number Diff line change @@ -126,7 +126,7 @@ public static function getNumericStorageId($storageId) {
126126 }
127127
128128 /**
129- * @return array [ available, last_checked ]
129+ * @return array{ available: bool , last_checked: int}
130130 */
131131 public function getAvailability () {
132132 if ($ row = self ::getStorageById ($ this ->storageId )) {
Original file line number Diff line number Diff line change @@ -710,7 +710,7 @@ private function getLockLogger(): ?LoggerInterface {
710710 }
711711
712712 /**
713- * @return array [ available, last_checked ]
713+ * @return array{ available: bool , last_checked: int}
714714 */
715715 public function getAvailability (): array {
716716 return $ this ->getStorageCache ()->getAvailability ();
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ class Availability extends Wrapper {
2222
2323 /** @var IConfig */
2424 protected $ config ;
25+ protected ?bool $ available = null ;
2526
2627 public function __construct (array $ parameters ) {
2728 $ this ->config = $ parameters ['config ' ] ?? \OCP \Server::get (IConfig::class);
@@ -54,11 +55,14 @@ private function updateAvailability(): bool {
5455 }
5556
5657 private function isAvailable (): bool {
57- $ availability = $ this ->getAvailability ();
58- if (self ::shouldRecheck ($ availability )) {
59- return $ this ->updateAvailability ();
58+ if (is_null ($ this ->available )) {
59+ $ availability = $ this ->getAvailability ();
60+ if (self ::shouldRecheck ($ availability )) {
61+ return $ this ->updateAvailability ();
62+ }
63+ $ this ->available = $ availability ['available ' ];
6064 }
61- return $ availability [ ' available ' ] ;
65+ return $ this -> available ;
6266 }
6367
6468 /**
@@ -257,6 +261,7 @@ protected function setUnavailable(?StorageNotAvailableException $e): void {
257261 self ::RECHECK_TTL_SEC
258262 );
259263 }
264+ $ this ->available = false ;
260265 $ this ->getStorageCache ()->setAvailability (false , $ delay );
261266 if ($ e !== null ) {
262267 throw $ e ;
Original file line number Diff line number Diff line change @@ -150,4 +150,30 @@ public function testAvailableThrow(): void {
150150
151151 $ this ->wrapper ->mkdir ('foobar ' );
152152 }
153+
154+ public function testUnavailableMultiple (): void {
155+ $ this ->storage ->expects ($ this ->once ())
156+ ->method ('getAvailability ' )
157+ ->willReturn (['available ' => true , 'last_checked ' => 0 ]);
158+ $ this ->storage ->expects ($ this ->never ())
159+ ->method ('test ' );
160+ $ this ->storage
161+ ->expects ($ this ->once ()) // load-bearing `once`
162+ ->method ('mkdir ' )
163+ ->willThrowException (new StorageNotAvailableException ());
164+
165+ try {
166+ $ this ->wrapper ->mkdir ('foobar ' );
167+ $ this ->fail ();
168+ } catch (StorageNotAvailableException ) {
169+ }
170+
171+ $ this ->storage ->expects ($ this ->never ())->method ('file_exists ' );
172+
173+ try {
174+ $ this ->wrapper ->mkdir ('foobar ' );
175+ $ this ->fail ();
176+ } catch (StorageNotAvailableException ) {
177+ }
178+ }
153179}
You can’t perform that action at this time.
0 commit comments