mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Implement graceful shutdown of agent.DataAccess (#1008)
* Implements graceful shutdown of agent.DataAccess and underlying Datastore/Logstore/MessageQueue * adds tests for closing agent.DataAccess and Datastore
This commit is contained in:
@@ -116,3 +116,8 @@ func (m *metricds) GetLog(ctx context.Context, appName, callID string) (io.Reade
|
||||
|
||||
// instant & no context ;)
|
||||
func (m *metricds) GetDatabase() *sqlx.DB { return m.ds.GetDatabase() }
|
||||
|
||||
// Close calls Close on the underlying Datastore
|
||||
func (m *metricds) Close() error {
|
||||
return m.ds.Close()
|
||||
}
|
||||
|
||||
@@ -198,3 +198,7 @@ func (m *mock) batchDeleteRoutes(ctx context.Context, appID string) error {
|
||||
func (m *mock) GetDatabase() *sqlx.DB {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *mock) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -910,3 +910,8 @@ func buildFilterCallQuery(filter *models.CallFilter) (string, []interface{}) {
|
||||
func (ds *sqlStore) GetDatabase() *sqlx.DB {
|
||||
return ds.db
|
||||
}
|
||||
|
||||
// Close closes the database, releasing any open resources.
|
||||
func (ds *sqlStore) Close() error {
|
||||
return ds.db.Close()
|
||||
}
|
||||
|
||||
@@ -127,4 +127,23 @@ func TestDatastore(t *testing.T) {
|
||||
|
||||
both(u)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestClose(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
defer os.RemoveAll("sqlite_test_dir")
|
||||
u, err := url.Parse("sqlite3://sqlite_test_dir")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
os.RemoveAll("sqlite_test_dir")
|
||||
ds, err := newDS(ctx, u)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := ds.Close(); err != nil {
|
||||
t.Fatalf("Failed to close datastore: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user