@@ -44,6 +44,11 @@ func TestInstanceManager(t *testing.T) {
44
44
Updated : time .Now (),
45
45
},
46
46
}
47
+ origDisposeTTL := disposeTTL
48
+ disposeTTL = time .Millisecond
49
+ t .Cleanup (func () {
50
+ disposeTTL = origDisposeTTL
51
+ })
47
52
newInstance , err := im .Get (ctx , pCtxUpdated )
48
53
49
54
t .Run ("New instance should be created" , func (t * testing.T ) {
@@ -66,44 +71,6 @@ func TestInstanceManager(t *testing.T) {
66
71
})
67
72
}
68
73
69
- func TestInstanceManagerExpiration (t * testing.T ) {
70
- ctx := context .Background ()
71
- pCtx := backend.PluginContext {
72
- OrgID : 1 ,
73
- AppInstanceSettings : & backend.AppInstanceSettings {
74
- Updated : time .Now (),
75
- },
76
- }
77
-
78
- tip := & testInstanceProvider {}
79
- im := newTTLInstanceManager (tip , time .Millisecond , 2 * time .Millisecond )
80
-
81
- instance , err := im .Get (ctx , pCtx )
82
- require .NoError (t , err )
83
- require .NotNil (t , instance )
84
- require .Equal (t , pCtx .OrgID , instance .(* testInstance ).orgID )
85
- require .Equal (t , pCtx .AppInstanceSettings .Updated , instance .(* testInstance ).updated )
86
-
87
- t .Run ("After expiration" , func (t * testing.T ) {
88
- instance .(* testInstance ).wg .Wait ()
89
- require .True (t , instance .(* testInstance ).disposed .Load ())
90
- require .Equal (t , int64 (1 ), instance .(* testInstance ).disposedTimes .Load ())
91
-
92
- newInstance , err := im .Get (ctx , pCtx )
93
-
94
- t .Run ("New instance should be created" , func (t * testing.T ) {
95
- require .NoError (t , err )
96
- require .NotNil (t , newInstance )
97
- require .Equal (t , pCtx .OrgID , newInstance .(* testInstance ).orgID )
98
- require .Equal (t , pCtx .AppInstanceSettings .Updated , newInstance .(* testInstance ).updated )
99
- })
100
-
101
- t .Run ("New instance should not be the same as old instance" , func (t * testing.T ) {
102
- require .NotSame (t , instance , newInstance )
103
- })
104
- })
105
- }
106
-
107
74
func TestInstanceManagerConcurrency (t * testing.T ) {
108
75
t .Run ("Check possible race condition issues when initially creating instance" , func (t * testing.T ) {
109
76
ctx := context .Background ()
@@ -144,6 +111,12 @@ func TestInstanceManagerConcurrency(t *testing.T) {
144
111
})
145
112
146
113
t .Run ("Check possible race condition issues when re-creating instance on settings update" , func (t * testing.T ) {
114
+ origDisposeTTL := disposeTTL
115
+ disposeTTL = time .Millisecond
116
+ t .Cleanup (func () {
117
+ disposeTTL = origDisposeTTL
118
+ })
119
+
147
120
ctx := context .Background ()
148
121
initialPCtx := backend.PluginContext {
149
122
OrgID : 1 ,
@@ -152,7 +125,7 @@ func TestInstanceManagerConcurrency(t *testing.T) {
152
125
},
153
126
}
154
127
tip := & testInstanceProvider {}
155
- im := newTTLInstanceManager (tip , defaultInstanceTTL , defaultInstanceCleanupInterval )
128
+ im := New (tip )
156
129
// Creating initial instance with old contexts
157
130
instanceToDispose , _ := im .Get (ctx , initialPCtx )
158
131
0 commit comments