11const chai = require ( 'chai' ) ;
2+ const { KILOBYTE , MEGABYTE } = require ( '../../src/constants' ) ;
23const expect = chai . expect ;
34
45describe ( 'HTTP/HTTPS Performance Tests' , ( ) => {
56 describe ( 'Memory Usage Tests' , ( ) => {
67 it ( 'should handle small POST requests efficiently' , async ( ) => {
7- const smallData = Buffer . alloc ( 1024 ) ; // 1KB
8+ const smallData = Buffer . alloc ( 1 * KILOBYTE ) ;
89 const startMemory = process . memoryUsage ( ) . heapUsed ;
910
1011 // Simulate request processing
@@ -20,12 +21,12 @@ describe('HTTP/HTTPS Performance Tests', () => {
2021 const endMemory = process . memoryUsage ( ) . heapUsed ;
2122 const memoryIncrease = endMemory - startMemory ;
2223
23- expect ( memoryIncrease ) . to . be . lessThan ( 1024 * 5 ) ; // Should use less than 5KB
24- expect ( req . body . length ) . to . equal ( 1024 ) ;
24+ expect ( memoryIncrease ) . to . be . lessThan ( KILOBYTE * 5 ) ; // Should use less than 5KB
25+ expect ( req . body . length ) . to . equal ( KILOBYTE ) ;
2526 } ) ;
2627
2728 it ( 'should handle medium POST requests within reasonable limits' , async ( ) => {
28- const mediumData = Buffer . alloc ( 10 * 1024 * 1024 ) ; // 10MB
29+ const mediumData = Buffer . alloc ( 10 * MEGABYTE ) ;
2930 const startMemory = process . memoryUsage ( ) . heapUsed ;
3031
3132 // Simulate request processing
@@ -41,12 +42,12 @@ describe('HTTP/HTTPS Performance Tests', () => {
4142 const endMemory = process . memoryUsage ( ) . heapUsed ;
4243 const memoryIncrease = endMemory - startMemory ;
4344
44- expect ( memoryIncrease ) . to . be . lessThan ( 15 * 1024 * 1024 ) ; // Should use less than 15MB
45- expect ( req . body . length ) . to . equal ( 10 * 1024 * 1024 ) ;
45+ expect ( memoryIncrease ) . to . be . lessThan ( 15 * MEGABYTE ) ; // Should use less than 15MB
46+ expect ( req . body . length ) . to . equal ( 10 * MEGABYTE ) ;
4647 } ) ;
4748
4849 it ( 'should handle large POST requests up to size limit' , async ( ) => {
49- const largeData = Buffer . alloc ( 100 * 1024 * 1024 ) ; // 100MB
50+ const largeData = Buffer . alloc ( 100 * MEGABYTE ) ;
5051 const startMemory = process . memoryUsage ( ) . heapUsed ;
5152
5253 // Simulate request processing
@@ -62,25 +63,25 @@ describe('HTTP/HTTPS Performance Tests', () => {
6263 const endMemory = process . memoryUsage ( ) . heapUsed ;
6364 const memoryIncrease = endMemory - startMemory ;
6465
65- expect ( memoryIncrease ) . to . be . lessThan ( 120 * 1024 * 1024 ) ; // Should use less than 120MB
66- expect ( req . body . length ) . to . equal ( 100 * 1024 * 1024 ) ;
66+ expect ( memoryIncrease ) . to . be . lessThan ( 120 * MEGABYTE ) ; // Should use less than 120MB
67+ expect ( req . body . length ) . to . equal ( 100 * MEGABYTE ) ;
6768 } ) ;
6869
6970 it ( 'should reject requests exceeding size limit' , async ( ) => {
70- const oversizedData = Buffer . alloc ( 1200 * 1024 * 1024 ) ; // 1.2GB (exceeds 1GB limit)
71+ const oversizedData = Buffer . alloc ( 1200 * MEGABYTE ) ; // 1.2GB (exceeds 1GB limit)
7172
7273 // Simulate size check
73- const maxPackSize = 1024 * 1024 * 1024 ;
74+ const maxPackSize = 1 * GIGABYTE ;
7475 const requestSize = oversizedData . length ;
7576
7677 expect ( requestSize ) . to . be . greaterThan ( maxPackSize ) ;
77- expect ( requestSize ) . to . equal ( 1200 * 1024 * 1024 ) ;
78+ expect ( requestSize ) . to . equal ( 1200 * MEGABYTE ) ;
7879 } ) ;
7980 } ) ;
8081
8182 describe ( 'Processing Time Tests' , ( ) => {
8283 it ( 'should process small requests quickly' , async ( ) => {
83- const smallData = Buffer . alloc ( 1024 ) ; // 1KB
84+ const smallData = Buffer . alloc ( 1 * KILOBYTE ) ;
8485 const startTime = Date . now ( ) ;
8586
8687 // Simulate processing
@@ -96,11 +97,11 @@ describe('HTTP/HTTPS Performance Tests', () => {
9697 const processingTime = Date . now ( ) - startTime ;
9798
9899 expect ( processingTime ) . to . be . lessThan ( 100 ) ; // Should complete in less than 100ms
99- expect ( req . body . length ) . to . equal ( 1024 ) ;
100+ expect ( req . body . length ) . to . equal ( 1 * KILOBYTE ) ;
100101 } ) ;
101102
102103 it ( 'should process medium requests within acceptable time' , async ( ) => {
103- const mediumData = Buffer . alloc ( 10 * 1024 * 1024 ) ; // 10MB
104+ const mediumData = Buffer . alloc ( 10 * MEGABYTE ) ;
104105 const startTime = Date . now ( ) ;
105106
106107 // Simulate processing
@@ -116,11 +117,11 @@ describe('HTTP/HTTPS Performance Tests', () => {
116117 const processingTime = Date . now ( ) - startTime ;
117118
118119 expect ( processingTime ) . to . be . lessThan ( 1000 ) ; // Should complete in less than 1 second
119- expect ( req . body . length ) . to . equal ( 10 * 1024 * 1024 ) ;
120+ expect ( req . body . length ) . to . equal ( 10 * MEGABYTE ) ;
120121 } ) ;
121122
122123 it ( 'should process large requests within reasonable time' , async ( ) => {
123- const largeData = Buffer . alloc ( 100 * 1024 * 1024 ) ; // 100MB
124+ const largeData = Buffer . alloc ( 100 * MEGABYTE ) ;
124125 const startTime = Date . now ( ) ;
125126
126127 // Simulate processing
@@ -136,7 +137,7 @@ describe('HTTP/HTTPS Performance Tests', () => {
136137 const processingTime = Date . now ( ) - startTime ;
137138
138139 expect ( processingTime ) . to . be . lessThan ( 5000 ) ; // Should complete in less than 5 seconds
139- expect ( req . body . length ) . to . equal ( 100 * 1024 * 1024 ) ;
140+ expect ( req . body . length ) . to . equal ( 100 * MEGABYTE ) ;
140141 } ) ;
141142 } ) ;
142143
@@ -148,7 +149,7 @@ describe('HTTP/HTTPS Performance Tests', () => {
148149 // Simulate 10 concurrent small requests
149150 for ( let i = 0 ; i < 10 ; i ++ ) {
150151 const request = new Promise ( ( resolve ) => {
151- const smallData = Buffer . alloc ( 1024 ) ;
152+ const smallData = Buffer . alloc ( 1 * KILOBYTE ) ;
152153 const req = {
153154 method : 'POST' ,
154155 url : '/github.com/test/test-repo.git/git-receive-pack' ,
@@ -168,7 +169,7 @@ describe('HTTP/HTTPS Performance Tests', () => {
168169 expect ( results ) . to . have . length ( 10 ) ;
169170 expect ( totalTime ) . to . be . lessThan ( 1000 ) ; // Should complete all in less than 1 second
170171 results . forEach ( ( result ) => {
171- expect ( result . body . length ) . to . equal ( 1024 ) ;
172+ expect ( result . body . length ) . to . equal ( 1 * KILOBYTE ) ;
172173 } ) ;
173174 } ) ;
174175
@@ -177,7 +178,7 @@ describe('HTTP/HTTPS Performance Tests', () => {
177178 const startTime = Date . now ( ) ;
178179
179180 // Simulate mixed operations
180- const sizes = [ 1024 , 1024 * 1024 , 10 * 1024 * 1024 ] ; // 1KB, 1MB, 10MB
181+ const sizes = [ 1 * KILOBYTE , 1 * MEGABYTE , 10 * MEGABYTE ] ;
181182
182183 for ( let i = 0 ; i < 9 ; i ++ ) {
183184 const request = new Promise ( ( resolve ) => {
@@ -226,7 +227,7 @@ describe('HTTP/HTTPS Performance Tests', () => {
226227 const processingTime = endTime - startTime ;
227228
228229 expect ( processingTime ) . to . be . lessThan ( 100 ) ; // Should handle errors quickly
229- expect ( memoryIncrease ) . to . be . lessThan ( 2048 ) ; // Should not leak memory (allow for GC timing)
230+ expect ( memoryIncrease ) . to . be . lessThan ( 2 * KILOBYTE ) ; // Should not leak memory (allow for GC timing)
230231 } ) ;
231232
232233 it ( 'should handle malformed requests efficiently' , async ( ) => {
@@ -239,7 +240,7 @@ describe('HTTP/HTTPS Performance Tests', () => {
239240 headers : {
240241 'content-type' : 'application/x-git-receive-pack-request' ,
241242 } ,
242- body : Buffer . alloc ( 1024 ) ,
243+ body : Buffer . alloc ( 1 * KILOBYTE ) ,
243244 } ;
244245
245246 // Simulate validation
@@ -256,24 +257,24 @@ describe('HTTP/HTTPS Performance Tests', () => {
256257 const startMemory = process . memoryUsage ( ) . heapUsed ;
257258
258259 // Simulate processing with cleanup
259- const data = Buffer . alloc ( 10 * 1024 * 1024 ) ; // 10MB
260+ const data = Buffer . alloc ( 10 * MEGABYTE ) ;
260261 const _processedData = Buffer . concat ( [ data ] ) ;
261262
262263 // Simulate cleanup
263264 data . fill ( 0 ) ; // Clear buffer
264265 const cleanedMemory = process . memoryUsage ( ) . heapUsed ;
265266
266- expect ( _processedData . length ) . to . equal ( 10 * 1024 * 1024 ) ;
267+ expect ( _processedData . length ) . to . equal ( 10 * MEGABYTE ) ;
267268 // Memory should be similar to start (allowing for GC timing)
268- expect ( cleanedMemory - startMemory ) . to . be . lessThan ( 5 * 1024 * 1024 ) ;
269+ expect ( cleanedMemory - startMemory ) . to . be . lessThan ( 5 * MEGABYTE ) ;
269270 } ) ;
270271
271272 it ( 'should handle multiple cleanup cycles without memory growth' , async ( ) => {
272273 const initialMemory = process . memoryUsage ( ) . heapUsed ;
273274
274275 // Simulate multiple processing cycles
275276 for ( let i = 0 ; i < 5 ; i ++ ) {
276- const data = Buffer . alloc ( 5 * 1024 * 1024 ) ; // 5MB
277+ const data = Buffer . alloc ( 5 * MEGABYTE ) ;
277278 const _processedData = Buffer . concat ( [ data ] ) ;
278279 data . fill ( 0 ) ; // Cleanup
279280
@@ -287,7 +288,7 @@ describe('HTTP/HTTPS Performance Tests', () => {
287288 const memoryGrowth = finalMemory - initialMemory ;
288289
289290 // Memory growth should be minimal
290- expect ( memoryGrowth ) . to . be . lessThan ( 10 * 1024 * 1024 ) ; // Less than 10MB growth
291+ expect ( memoryGrowth ) . to . be . lessThan ( 10 * MEGABYTE ) ; // Less than 10MB growth
291292 } ) ;
292293 } ) ;
293294
@@ -298,7 +299,7 @@ describe('HTTP/HTTPS Performance Tests', () => {
298299 // Simulate config loading
299300 const testConfig = {
300301 proxy : { port : 8000 , host : 'localhost' } ,
301- limits : { maxPackSizeBytes : 1024 * 1024 * 1024 } ,
302+ limits : { maxPackSizeBytes : 1 * GIGABYTE } ,
302303 } ;
303304
304305 const endTime = Date . now ( ) ;
@@ -315,7 +316,7 @@ describe('HTTP/HTTPS Performance Tests', () => {
315316 // Simulate config validation
316317 const testConfig = {
317318 proxy : { port : 8000 } ,
318- limits : { maxPackSizeBytes : 1024 * 1024 * 1024 } ,
319+ limits : { maxPackSizeBytes : 1 * GIGABYTE } ,
319320 } ;
320321 const isValid = testConfig . proxy . port > 0 && testConfig . limits . maxPackSizeBytes > 0 ;
321322
0 commit comments