@@ -146,6 +146,48 @@ func getChildren(cluster *clusterCache, un *unstructured.Unstructured) []*Resour
146
146
return hierarchy [1 :]
147
147
}
148
148
149
+ // Benchmark_sync is meant to simulate cluster initialization when populateResourceInfoHandler does nontrivial work.
150
+ func Benchmark_sync (t * testing.B ) {
151
+ var resources = []runtime.Object {}
152
+ for i := 0 ; i < 100 ; i ++ {
153
+ resources = append (resources , & corev1.Pod {
154
+ ObjectMeta : metav1.ObjectMeta {
155
+ Name : fmt .Sprintf ("pod-%d" , i ),
156
+ Namespace : "default" ,
157
+ },
158
+ }, & appsv1.ReplicaSet {
159
+ ObjectMeta : metav1.ObjectMeta {
160
+ Name : fmt .Sprintf ("rs-%d" , i ),
161
+ Namespace : "default" ,
162
+ },
163
+ }, & appsv1.Deployment {
164
+ ObjectMeta : metav1.ObjectMeta {
165
+ Name : fmt .Sprintf ("deploy-%d" , i ),
166
+ Namespace : "default" ,
167
+ },
168
+ }, & appsv1.StatefulSet {
169
+ ObjectMeta : metav1.ObjectMeta {
170
+ Name : fmt .Sprintf ("sts-%d" , i ),
171
+ Namespace : "default" ,
172
+ },
173
+ })
174
+ }
175
+
176
+ c := newCluster (t , resources ... )
177
+
178
+ c .populateResourceInfoHandler = func (un * unstructured.Unstructured , isRoot bool ) (info interface {}, cacheManifest bool ) {
179
+ time .Sleep (10 * time .Microsecond )
180
+ return nil , false
181
+ }
182
+
183
+ t .ResetTimer ()
184
+
185
+ for n := 0 ; n < t .N ; n ++ {
186
+ err := c .sync ()
187
+ require .NoError (t , err )
188
+ }
189
+ }
190
+
149
191
func TestEnsureSynced (t * testing.T ) {
150
192
obj1 := & appsv1.Deployment {
151
193
TypeMeta : metav1.TypeMeta {
0 commit comments