summaryrefslogtreecommitdiff
path: root/tests/FundLab.Api.Tests/PersistenceTests.fs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/FundLab.Api.Tests/PersistenceTests.fs')
-rw-r--r--tests/FundLab.Api.Tests/PersistenceTests.fs51
1 files changed, 49 insertions, 2 deletions
diff --git a/tests/FundLab.Api.Tests/PersistenceTests.fs b/tests/FundLab.Api.Tests/PersistenceTests.fs
index 5157a9c..64e857c 100644
--- a/tests/FundLab.Api.Tests/PersistenceTests.fs
+++ b/tests/FundLab.Api.Tests/PersistenceTests.fs
@@ -695,8 +695,8 @@ type PersistenceTests(fixture: PostgresFixture) =
let marketData =
{ new IMarketDataService with
- member _.Search _ = Ok searchPayload
- member _.RefreshNav _ = Ok [ observation ]
+ member _.Search(_, _) = Ok searchPayload
+ member _.RefreshNav(_, _) = Ok [ observation ]
member _.GetNav(_, _, _) = Ok [ observation ] }
let app = App.createApplicationWithMarketData (repository ()) marketData
@@ -726,6 +726,53 @@ type PersistenceTests(fixture: PostgresFixture) =
Assert.Contains("\"source\":\"akshare\"", navBody)
[<Fact>]
+ member _.``market data API keeps collector failures and process tree out of HTTP responses``() =
+ let dir = Path.Combine(Path.GetTempPath(), "fund-lab-collector-" + Guid.NewGuid().ToString("N"))
+
+ Directory.CreateDirectory(dir) |> ignore
+
+ try
+ let scriptPath = Path.Combine(dir, "hang.sh")
+
+ File.WriteAllText(
+ scriptPath,
+ "printf 'secret=%s\\n' 'fund-lab-HTTP-SENTINEL' >&2\nsleep 60 & child=$!\necho $child > pidfile\nwait $child\n"
+ )
+
+ let collector =
+ ProcessMarketDataCollector("/bin/sh", scriptPath, None, 1) :> IMarketDataCollector
+
+ let marketData = MarketDataService(repository (), collector)
+ let app = App.createApplicationWithMarketData (repository ()) marketData
+
+ let status, responseBody =
+ PersistenceTestHelpers.invoke
+ app
+ "GET"
+ "/api/instruments/search?q=000001"
+ [ "Authorization", "Bearer test-token" ]
+ ""
+
+ Assert.Equal(503, status)
+ Assert.Contains("MARKET_DATA_UNAVAILABLE", responseBody)
+ Assert.Contains("did not finish within 1 seconds", responseBody)
+ Assert.DoesNotContain(dir, responseBody)
+ Assert.DoesNotContain("fund-lab-HTTP-SENTINEL", responseBody)
+
+ let recordedPid = Int32.Parse(File.ReadAllText(Path.Combine(dir, "pidfile")).Trim())
+ let mutable dead = not (Directory.Exists(sprintf "/proc/%d" recordedPid))
+ let mutable waited = 0
+
+ while not dead && waited < 10000 do
+ Thread.Sleep(100)
+ waited <- waited + 100
+ dead <- not (Directory.Exists(sprintf "/proc/%d" recordedPid))
+
+ Assert.True(dead, "backgrounded subprocess survived the HTTP timeout")
+ finally
+ Directory.Delete(dir, true)
+
+ [<Fact>]
member _.``fund API rejects non-object JSON bodies``() =
let app = App.createApplication (repository ())