diff --git a/container/garray/garray_func.go b/container/garray/garray_func.go index 364654084..155cca0d8 100644 --- a/container/garray/garray_func.go +++ b/container/garray/garray_func.go @@ -8,11 +8,6 @@ package garray import "strings" -// iInterfaces is used for type assert api for Interfaces. -type iInterfaces interface { - Interfaces() []interface{} -} - // defaultComparatorInt for int comparison. func defaultComparatorInt(a, b int) int { if a < b { diff --git a/container/garray/garray_z_example_any_test.go b/container/garray/garray_z_example_normal_any_test.go similarity index 100% rename from container/garray/garray_z_example_any_test.go rename to container/garray/garray_z_example_normal_any_test.go diff --git a/container/garray/garray_z_example_int_test.go b/container/garray/garray_z_example_normal_int_test.go similarity index 100% rename from container/garray/garray_z_example_int_test.go rename to container/garray/garray_z_example_normal_int_test.go diff --git a/container/garray/garray_z_example_str_test.go b/container/garray/garray_z_example_normal_str_test.go similarity index 97% rename from container/garray/garray_z_example_str_test.go rename to container/garray/garray_z_example_normal_str_test.go index a7efa9692..0444cc676 100644 --- a/container/garray/garray_z_example_str_test.go +++ b/container/garray/garray_z_example_normal_str_test.go @@ -31,7 +31,7 @@ func ExampleStrArray_Walk() { // [gf_user gf_user_detail] } -func ExampleStrArray_NewStrArray() { +func ExampleNewStrArray() { s := garray.NewStrArray() s.Append("We") s.Append("are") @@ -43,7 +43,7 @@ func ExampleStrArray_NewStrArray() { // [We are GF fans] } -func ExampleStrArray_NewStrArraySize() { +func ExampleNewStrArraySize() { s := garray.NewStrArraySize(3, 5) s.Set(0, "We") s.Set(1, "are") @@ -55,7 +55,7 @@ func ExampleStrArray_NewStrArraySize() { // [We are GF] 3 5 } -func ExampleStrArray_NewStrArrayFrom() { +func ExampleNewStrArrayFrom() { s := garray.NewStrArrayFrom(g.SliceStr{"We", "are", "GF", "fans", "!"}) fmt.Println(s.Slice(), s.Len(), cap(s.Slice())) @@ -63,14 +63,6 @@ func ExampleStrArray_NewStrArrayFrom() { // [We are GF fans !] 5 5 } -func ExampleStrArray_NewStrArrayFromCopy() { - s := garray.NewStrArrayFromCopy(g.SliceStr{"We", "are", "GF", "fans", "!"}) - fmt.Println(s.Slice(), s.Len(), cap(s.Slice())) - - // Output: - // [We are GF fans !] 5 5 -} - func ExampleStrArray_At() { s := garray.NewStrArrayFrom(g.SliceStr{"We", "are", "GF", "fans", "!"}) sAt := s.At(2) diff --git a/container/garray/garray_z_unit_normal_any_array_test.go b/container/garray/garray_z_unit_normal_any_test.go similarity index 100% rename from container/garray/garray_z_unit_normal_any_array_test.go rename to container/garray/garray_z_unit_normal_any_test.go diff --git a/container/garray/garray_z_unit_normal_int_array_test.go b/container/garray/garray_z_unit_normal_int_test.go similarity index 100% rename from container/garray/garray_z_unit_normal_int_array_test.go rename to container/garray/garray_z_unit_normal_int_test.go diff --git a/container/garray/garray_z_unit_normal_str_array_test.go b/container/garray/garray_z_unit_normal_str_test.go similarity index 100% rename from container/garray/garray_z_unit_normal_str_array_test.go rename to container/garray/garray_z_unit_normal_str_test.go diff --git a/container/garray/garray_z_unit_sorted_any_array_test.go b/container/garray/garray_z_unit_sorted_any_test.go similarity index 100% rename from container/garray/garray_z_unit_sorted_any_array_test.go rename to container/garray/garray_z_unit_sorted_any_test.go diff --git a/container/garray/garray_z_unit_sorted_int_array_test.go b/container/garray/garray_z_unit_sorted_int_test.go similarity index 100% rename from container/garray/garray_z_unit_sorted_int_array_test.go rename to container/garray/garray_z_unit_sorted_int_test.go diff --git a/container/garray/garray_z_unit_sorted_str_array_test.go b/container/garray/garray_z_unit_sorted_str_test.go similarity index 100% rename from container/garray/garray_z_unit_sorted_str_array_test.go rename to container/garray/garray_z_unit_sorted_str_test.go diff --git a/container/gmap/gmap_z_unit_any_any_test.go b/container/gmap/gmap_z_unit_hash_any_any_test.go similarity index 100% rename from container/gmap/gmap_z_unit_any_any_test.go rename to container/gmap/gmap_z_unit_hash_any_any_test.go diff --git a/container/gmap/gmap_z_unit_int_any_test.go b/container/gmap/gmap_z_unit_hash_int_any_test.go similarity index 100% rename from container/gmap/gmap_z_unit_int_any_test.go rename to container/gmap/gmap_z_unit_hash_int_any_test.go diff --git a/container/gmap/gmap_z_unit_int_int_test.go b/container/gmap/gmap_z_unit_hash_int_int_test.go similarity index 100% rename from container/gmap/gmap_z_unit_int_int_test.go rename to container/gmap/gmap_z_unit_hash_int_int_test.go diff --git a/container/gmap/gmap_z_unit_int_str_test.go b/container/gmap/gmap_z_unit_hash_int_str_test.go similarity index 100% rename from container/gmap/gmap_z_unit_int_str_test.go rename to container/gmap/gmap_z_unit_hash_int_str_test.go diff --git a/container/gmap/gmap_z_unit_str_any_test.go b/container/gmap/gmap_z_unit_hash_str_any_test.go similarity index 100% rename from container/gmap/gmap_z_unit_str_any_test.go rename to container/gmap/gmap_z_unit_hash_str_any_test.go diff --git a/container/gmap/gmap_z_unit_str_int_test.go b/container/gmap/gmap_z_unit_hash_str_int_test.go similarity index 100% rename from container/gmap/gmap_z_unit_str_int_test.go rename to container/gmap/gmap_z_unit_hash_str_int_test.go diff --git a/container/gmap/gmap_z_unit_str_str_test.go b/container/gmap/gmap_z_unit_hash_str_str_test.go similarity index 100% rename from container/gmap/gmap_z_unit_str_str_test.go rename to container/gmap/gmap_z_unit_hash_str_str_test.go diff --git a/container/gring/gring_bench_test.go b/container/gring/gring_z_bench_test.go similarity index 100% rename from container/gring/gring_bench_test.go rename to container/gring/gring_z_bench_test.go diff --git a/container/gring/gring_unit_test.go b/container/gring/gring_z_unit_test.go similarity index 100% rename from container/gring/gring_unit_test.go rename to container/gring/gring_z_unit_test.go diff --git a/crypto/gaes/gaes_test.go b/crypto/gaes/gaes_z_unit_test.go similarity index 100% rename from crypto/gaes/gaes_test.go rename to crypto/gaes/gaes_z_unit_test.go diff --git a/crypto/gcrc32/gcrc32_test.go b/crypto/gcrc32/gcrc32_z_unit_test.go similarity index 100% rename from crypto/gcrc32/gcrc32_test.go rename to crypto/gcrc32/gcrc32_z_unit_test.go diff --git a/crypto/gdes/gdes_test.go b/crypto/gdes/gdes_z_unit_test.go similarity index 100% rename from crypto/gdes/gdes_test.go rename to crypto/gdes/gdes_z_unit_test.go diff --git a/crypto/gmd5/gmd5_test.go b/crypto/gmd5/gmd5_z_unit_test.go similarity index 100% rename from crypto/gmd5/gmd5_test.go rename to crypto/gmd5/gmd5_z_unit_test.go diff --git a/crypto/gsha1/gsha1_test.go b/crypto/gsha1/gsha1_z_unit_test.go similarity index 100% rename from crypto/gsha1/gsha1_test.go rename to crypto/gsha1/gsha1_z_unit_test.go diff --git a/encoding/gbase64/gbase64_test.go b/encoding/gbase64/gbase64_z_unit_test.go similarity index 100% rename from encoding/gbase64/gbase64_test.go rename to encoding/gbase64/gbase64_z_unit_test.go diff --git a/encoding/gbinary/gbinary_z_be_test.go b/encoding/gbinary/gbinary_z_unit_be_test.go similarity index 100% rename from encoding/gbinary/gbinary_z_be_test.go rename to encoding/gbinary/gbinary_z_unit_be_test.go diff --git a/encoding/gbinary/gbinary_z_le_test.go b/encoding/gbinary/gbinary_z_unit_le_test.go similarity index 100% rename from encoding/gbinary/gbinary_z_le_test.go rename to encoding/gbinary/gbinary_z_unit_le_test.go diff --git a/encoding/gbinary/gbinary_z_test.go b/encoding/gbinary/gbinary_z_unit_test.go similarity index 100% rename from encoding/gbinary/gbinary_z_test.go rename to encoding/gbinary/gbinary_z_unit_test.go diff --git a/encoding/gcharset/gcharset_test.go b/encoding/gcharset/gcharset_z_unit_test.go similarity index 100% rename from encoding/gcharset/gcharset_test.go rename to encoding/gcharset/gcharset_z_unit_test.go diff --git a/encoding/ghash/ghash_bench_test.go b/encoding/ghash/ghash_z_bench_test.go similarity index 100% rename from encoding/ghash/ghash_bench_test.go rename to encoding/ghash/ghash_z_bench_test.go diff --git a/encoding/ghash/ghash_z_unit_basic_test.go b/encoding/ghash/ghash_z_unit_test.go similarity index 100% rename from encoding/ghash/ghash_z_unit_basic_test.go rename to encoding/ghash/ghash_z_unit_test.go diff --git a/encoding/ghtml/ghtml_test.go b/encoding/ghtml/ghtml_z_unit_test.go similarity index 100% rename from encoding/ghtml/ghtml_test.go rename to encoding/ghtml/ghtml_z_unit_test.go diff --git a/encoding/gini/gini_test.go b/encoding/gini/gini_z_unit_test.go similarity index 100% rename from encoding/gini/gini_test.go rename to encoding/gini/gini_z_unit_test.go diff --git a/encoding/gjson/gjson_z_unit_json_test.go b/encoding/gjson/gjson_z_unit_feature_json_test.go similarity index 100% rename from encoding/gjson/gjson_z_unit_json_test.go rename to encoding/gjson/gjson_z_unit_feature_json_test.go diff --git a/encoding/gjson/gjson_z_unit_load_test.go b/encoding/gjson/gjson_z_unit_feature_load_test.go similarity index 100% rename from encoding/gjson/gjson_z_unit_load_test.go rename to encoding/gjson/gjson_z_unit_feature_load_test.go diff --git a/encoding/gjson/gjson_z_unit_new_test.go b/encoding/gjson/gjson_z_unit_feature_new_test.go similarity index 100% rename from encoding/gjson/gjson_z_unit_new_test.go rename to encoding/gjson/gjson_z_unit_feature_new_test.go diff --git a/encoding/gjson/gjson_z_unit_set_test.go b/encoding/gjson/gjson_z_unit_feature_set_test.go similarity index 100% rename from encoding/gjson/gjson_z_unit_set_test.go rename to encoding/gjson/gjson_z_unit_feature_set_test.go diff --git a/encoding/gjson/gjson_z_unit_struct_test.go b/encoding/gjson/gjson_z_unit_feature_struct_test.go similarity index 100% rename from encoding/gjson/gjson_z_unit_struct_test.go rename to encoding/gjson/gjson_z_unit_feature_struct_test.go diff --git a/encoding/gjson/gjson_z_unit_basic_test.go b/encoding/gjson/gjson_z_unit_test.go similarity index 100% rename from encoding/gjson/gjson_z_unit_basic_test.go rename to encoding/gjson/gjson_z_unit_test.go diff --git a/encoding/gtoml/gtoml_test.go b/encoding/gtoml/gtoml_z_unit_test.go similarity index 100% rename from encoding/gtoml/gtoml_test.go rename to encoding/gtoml/gtoml_z_unit_test.go diff --git a/encoding/gurl/url_test.go b/encoding/gurl/url_z_unit_test.go similarity index 100% rename from encoding/gurl/url_test.go rename to encoding/gurl/url_z_unit_test.go diff --git a/encoding/gxml/gxml_test.go b/encoding/gxml/gxml_z_unit_test.go similarity index 100% rename from encoding/gxml/gxml_test.go rename to encoding/gxml/gxml_z_unit_test.go diff --git a/encoding/gyaml/gyaml_test.go b/encoding/gyaml/gyaml_z_unit_test.go similarity index 100% rename from encoding/gyaml/gyaml_test.go rename to encoding/gyaml/gyaml_z_unit_test.go diff --git a/errors/gcode/gcode_test.go b/errors/gcode/gcode_z_unit_test.go similarity index 100% rename from errors/gcode/gcode_test.go rename to errors/gcode/gcode_z_unit_test.go diff --git a/frame/gins/gins_z_unit_basic_test.go b/frame/gins/gins_z_unit_test.go similarity index 100% rename from frame/gins/gins_z_unit_basic_test.go rename to frame/gins/gins_z_unit_test.go diff --git a/i18n/gi18n/gi18n_unit_test.go b/i18n/gi18n/gi18n_z_unit_test.go similarity index 100% rename from i18n/gi18n/gi18n_unit_test.go rename to i18n/gi18n/gi18n_z_unit_test.go diff --git a/internal/empty/empty_test.go b/internal/empty/empty_z_unit_test.go similarity index 100% rename from internal/empty/empty_test.go rename to internal/empty/empty_z_unit_test.go diff --git a/internal/utils/utils_z_is_test.go b/internal/utils/utils_z_unit_is_test.go similarity index 100% rename from internal/utils/utils_z_is_test.go rename to internal/utils/utils_z_unit_is_test.go diff --git a/internal/utils/utils_z_test.go b/internal/utils/utils_z_unit_test.go similarity index 100% rename from internal/utils/utils_z_test.go rename to internal/utils/utils_z_unit_test.go diff --git a/net/ghttp/ghttp_unit_init_test.go b/net/ghttp/ghttp_unit_init_test.go deleted file mode 100644 index 65a6855c4..000000000 --- a/net/ghttp/ghttp_unit_init_test.go +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright GoFrame Author(https://goframe.org). All Rights Reserved. -// -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, -// You can obtain one at https://github.com/gogf/gf. - -package ghttp_test - -import ( - "context" - - "github.com/gogf/gf/v2/container/garray" - "github.com/gogf/gf/v2/os/genv" -) - -var ( - ctx = context.TODO() - ports = garray.NewIntArray(true) -) - -func init() { - genv.Set("UNDER_TEST", "1") - for i := 7000; i <= 8000; i++ { - ports.Append(i) - } -} diff --git a/net/ghttp/ghttp_unit_client_dump_test.go b/net/ghttp/ghttp_z_unit_feature_client_dump_test.go similarity index 100% rename from net/ghttp/ghttp_unit_client_dump_test.go rename to net/ghttp/ghttp_z_unit_feature_client_dump_test.go diff --git a/net/ghttp/ghttp_unit_client_test.go b/net/ghttp/ghttp_z_unit_feature_client_test.go similarity index 100% rename from net/ghttp/ghttp_unit_client_test.go rename to net/ghttp/ghttp_z_unit_feature_client_test.go diff --git a/net/ghttp/ghttp_unit_config_test.go b/net/ghttp/ghttp_z_unit_feature_config_test.go similarity index 100% rename from net/ghttp/ghttp_unit_config_test.go rename to net/ghttp/ghttp_z_unit_feature_config_test.go diff --git a/net/ghttp/ghttp_unit_context_test.go b/net/ghttp/ghttp_z_unit_feature_context_test.go similarity index 100% rename from net/ghttp/ghttp_unit_context_test.go rename to net/ghttp/ghttp_z_unit_feature_context_test.go diff --git a/net/ghttp/ghttp_unit_cookie_test.go b/net/ghttp/ghttp_z_unit_feature_cookie_test.go similarity index 100% rename from net/ghttp/ghttp_unit_cookie_test.go rename to net/ghttp/ghttp_z_unit_feature_cookie_test.go diff --git a/net/ghttp/ghttp_unit_error_code_test.go b/net/ghttp/ghttp_z_unit_feature_error_code_test.go similarity index 100% rename from net/ghttp/ghttp_unit_error_code_test.go rename to net/ghttp/ghttp_z_unit_feature_error_code_test.go diff --git a/net/ghttp/ghttp_unit_https_test.go b/net/ghttp/ghttp_z_unit_feature_https_test.go similarity index 100% rename from net/ghttp/ghttp_unit_https_test.go rename to net/ghttp/ghttp_z_unit_feature_https_test.go diff --git a/net/ghttp/ghttp_unit_ip_test.go b/net/ghttp/ghttp_z_unit_feature_ip_test.go similarity index 100% rename from net/ghttp/ghttp_unit_ip_test.go rename to net/ghttp/ghttp_z_unit_feature_ip_test.go diff --git a/net/ghttp/ghttp_unit_log_test.go b/net/ghttp/ghttp_z_unit_feature_log_test.go similarity index 100% rename from net/ghttp/ghttp_unit_log_test.go rename to net/ghttp/ghttp_z_unit_feature_log_test.go diff --git a/net/ghttp/ghttp_unit_middleware_basic_test.go b/net/ghttp/ghttp_z_unit_feature_middleware_basic_test.go similarity index 100% rename from net/ghttp/ghttp_unit_middleware_basic_test.go rename to net/ghttp/ghttp_z_unit_feature_middleware_basic_test.go diff --git a/net/ghttp/ghttp_unit_middleware_cors_test.go b/net/ghttp/ghttp_z_unit_feature_middleware_cors_test.go similarity index 100% rename from net/ghttp/ghttp_unit_middleware_cors_test.go rename to net/ghttp/ghttp_z_unit_feature_middleware_cors_test.go diff --git a/net/ghttp/ghttp_unit_openapi_swagger_test.go b/net/ghttp/ghttp_z_unit_feature_openapi_swagger_test.go similarity index 100% rename from net/ghttp/ghttp_unit_openapi_swagger_test.go rename to net/ghttp/ghttp_z_unit_feature_openapi_swagger_test.go diff --git a/net/ghttp/ghttp_unit_pprof_test.go b/net/ghttp/ghttp_z_unit_feature_pprof_test.go similarity index 100% rename from net/ghttp/ghttp_unit_pprof_test.go rename to net/ghttp/ghttp_z_unit_feature_pprof_test.go diff --git a/net/ghttp/ghttp_unit_request_ctx_test.go b/net/ghttp/ghttp_z_unit_feature_request_ctx_test.go similarity index 100% rename from net/ghttp/ghttp_unit_request_ctx_test.go rename to net/ghttp/ghttp_z_unit_feature_request_ctx_test.go diff --git a/net/ghttp/ghttp_unit_request_file_test.go b/net/ghttp/ghttp_z_unit_feature_request_file_test.go similarity index 100% rename from net/ghttp/ghttp_unit_request_file_test.go rename to net/ghttp/ghttp_z_unit_feature_request_file_test.go diff --git a/net/ghttp/ghttp_unit_request_json_test.go b/net/ghttp/ghttp_z_unit_feature_request_json_test.go similarity index 100% rename from net/ghttp/ghttp_unit_request_json_test.go rename to net/ghttp/ghttp_z_unit_feature_request_json_test.go diff --git a/net/ghttp/ghttp_unit_request_page_test.go b/net/ghttp/ghttp_z_unit_feature_request_page_test.go similarity index 100% rename from net/ghttp/ghttp_unit_request_page_test.go rename to net/ghttp/ghttp_z_unit_feature_request_page_test.go diff --git a/net/ghttp/ghttp_unit_request_struct_test.go b/net/ghttp/ghttp_z_unit_feature_request_struct_test.go similarity index 100% rename from net/ghttp/ghttp_unit_request_struct_test.go rename to net/ghttp/ghttp_z_unit_feature_request_struct_test.go diff --git a/net/ghttp/ghttp_unit_request_test.go b/net/ghttp/ghttp_z_unit_feature_request_test.go similarity index 100% rename from net/ghttp/ghttp_unit_request_test.go rename to net/ghttp/ghttp_z_unit_feature_request_test.go diff --git a/net/ghttp/ghttp_unit_request_xml_test.go b/net/ghttp/ghttp_z_unit_feature_request_xml_test.go similarity index 100% rename from net/ghttp/ghttp_unit_request_xml_test.go rename to net/ghttp/ghttp_z_unit_feature_request_xml_test.go diff --git a/net/ghttp/ghttp_unit_router_basic_test.go b/net/ghttp/ghttp_z_unit_feature_router_basic_test.go similarity index 100% rename from net/ghttp/ghttp_unit_router_basic_test.go rename to net/ghttp/ghttp_z_unit_feature_router_basic_test.go diff --git a/net/ghttp/ghttp_unit_router_domain_basic_test.go b/net/ghttp/ghttp_z_unit_feature_router_domain_basic_test.go similarity index 100% rename from net/ghttp/ghttp_unit_router_domain_basic_test.go rename to net/ghttp/ghttp_z_unit_feature_router_domain_basic_test.go diff --git a/net/ghttp/ghttp_unit_router_domain_object_rest_test.go b/net/ghttp/ghttp_z_unit_feature_router_domain_object_rest_test.go similarity index 100% rename from net/ghttp/ghttp_unit_router_domain_object_rest_test.go rename to net/ghttp/ghttp_z_unit_feature_router_domain_object_rest_test.go diff --git a/net/ghttp/ghttp_unit_router_domain_object_test.go b/net/ghttp/ghttp_z_unit_feature_router_domain_object_test.go similarity index 100% rename from net/ghttp/ghttp_unit_router_domain_object_test.go rename to net/ghttp/ghttp_z_unit_feature_router_domain_object_test.go diff --git a/net/ghttp/ghttp_unit_router_exit_test.go b/net/ghttp/ghttp_z_unit_feature_router_exit_test.go similarity index 100% rename from net/ghttp/ghttp_unit_router_exit_test.go rename to net/ghttp/ghttp_z_unit_feature_router_exit_test.go diff --git a/net/ghttp/ghttp_unit_router_group_group_test.go b/net/ghttp/ghttp_z_unit_feature_router_group_group_test.go similarity index 100% rename from net/ghttp/ghttp_unit_router_group_group_test.go rename to net/ghttp/ghttp_z_unit_feature_router_group_group_test.go diff --git a/net/ghttp/ghttp_unit_router_group_hook_test.go b/net/ghttp/ghttp_z_unit_feature_router_group_hook_test.go similarity index 100% rename from net/ghttp/ghttp_unit_router_group_hook_test.go rename to net/ghttp/ghttp_z_unit_feature_router_group_hook_test.go diff --git a/net/ghttp/ghttp_unit_router_group_rest_test.go b/net/ghttp/ghttp_z_unit_feature_router_group_rest_test.go similarity index 100% rename from net/ghttp/ghttp_unit_router_group_rest_test.go rename to net/ghttp/ghttp_z_unit_feature_router_group_rest_test.go diff --git a/net/ghttp/ghttp_unit_router_group_test.go b/net/ghttp/ghttp_z_unit_feature_router_group_test.go similarity index 100% rename from net/ghttp/ghttp_unit_router_group_test.go rename to net/ghttp/ghttp_z_unit_feature_router_group_test.go diff --git a/net/ghttp/ghttp_unit_router_handler_extended_test.go b/net/ghttp/ghttp_z_unit_feature_router_handler_extended_test.go similarity index 100% rename from net/ghttp/ghttp_unit_router_handler_extended_test.go rename to net/ghttp/ghttp_z_unit_feature_router_handler_extended_test.go diff --git a/net/ghttp/ghttp_unit_router_hook_test.go b/net/ghttp/ghttp_z_unit_feature_router_hook_test.go similarity index 100% rename from net/ghttp/ghttp_unit_router_hook_test.go rename to net/ghttp/ghttp_z_unit_feature_router_hook_test.go diff --git a/net/ghttp/ghttp_unit_router_names_test.go b/net/ghttp/ghttp_z_unit_feature_router_names_test.go similarity index 100% rename from net/ghttp/ghttp_unit_router_names_test.go rename to net/ghttp/ghttp_z_unit_feature_router_names_test.go diff --git a/net/ghttp/ghttp_unit_router_object_rest1_test.go b/net/ghttp/ghttp_z_unit_feature_router_object_rest1_test.go similarity index 100% rename from net/ghttp/ghttp_unit_router_object_rest1_test.go rename to net/ghttp/ghttp_z_unit_feature_router_object_rest1_test.go diff --git a/net/ghttp/ghttp_unit_router_object_rest2_test.go b/net/ghttp/ghttp_z_unit_feature_router_object_rest2_test.go similarity index 100% rename from net/ghttp/ghttp_unit_router_object_rest2_test.go rename to net/ghttp/ghttp_z_unit_feature_router_object_rest2_test.go diff --git a/net/ghttp/ghttp_unit_router_object_test.go b/net/ghttp/ghttp_z_unit_feature_router_object_test.go similarity index 100% rename from net/ghttp/ghttp_unit_router_object_test.go rename to net/ghttp/ghttp_z_unit_feature_router_object_test.go diff --git a/net/ghttp/ghttp_unit_server_util_test.go b/net/ghttp/ghttp_z_unit_feature_server_util_test.go similarity index 100% rename from net/ghttp/ghttp_unit_server_util_test.go rename to net/ghttp/ghttp_z_unit_feature_server_util_test.go diff --git a/net/ghttp/ghttp_unit_session_test.go b/net/ghttp/ghttp_z_unit_feature_session_test.go similarity index 100% rename from net/ghttp/ghttp_unit_session_test.go rename to net/ghttp/ghttp_z_unit_feature_session_test.go diff --git a/net/ghttp/ghttp_unit_static_test.go b/net/ghttp/ghttp_z_unit_feature_static_test.go similarity index 100% rename from net/ghttp/ghttp_unit_static_test.go rename to net/ghttp/ghttp_z_unit_feature_static_test.go diff --git a/net/ghttp/ghttp_unit_status_test.go b/net/ghttp/ghttp_z_unit_feature_status_test.go similarity index 100% rename from net/ghttp/ghttp_unit_status_test.go rename to net/ghttp/ghttp_z_unit_feature_status_test.go diff --git a/net/ghttp/ghttp_unit_template_test.go b/net/ghttp/ghttp_z_unit_feature_template_test.go similarity index 100% rename from net/ghttp/ghttp_unit_template_test.go rename to net/ghttp/ghttp_z_unit_feature_template_test.go diff --git a/net/ghttp/ghttp_unit_websocket_client_test.go b/net/ghttp/ghttp_z_unit_feature_websocket_client_test.go similarity index 100% rename from net/ghttp/ghttp_unit_websocket_client_test.go rename to net/ghttp/ghttp_z_unit_feature_websocket_client_test.go diff --git a/net/ghttp/ghttp_unit_websocket_test.go b/net/ghttp/ghttp_z_unit_feature_websocket_test.go similarity index 100% rename from net/ghttp/ghttp_unit_websocket_test.go rename to net/ghttp/ghttp_z_unit_feature_websocket_test.go diff --git a/net/ghttp/ghttp_unit_mess_test.go b/net/ghttp/ghttp_z_unit_test.go similarity index 78% rename from net/ghttp/ghttp_unit_mess_test.go rename to net/ghttp/ghttp_z_unit_test.go index 6c8abaa0a..3114b25c7 100644 --- a/net/ghttp/ghttp_unit_mess_test.go +++ b/net/ghttp/ghttp_z_unit_test.go @@ -7,15 +7,30 @@ package ghttp_test import ( + "context" "fmt" "testing" "time" + "github.com/gogf/gf/v2/container/garray" "github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/net/ghttp" + "github.com/gogf/gf/v2/os/genv" "github.com/gogf/gf/v2/test/gtest" ) +var ( + ctx = context.TODO() + ports = garray.NewIntArray(true) +) + +func init() { + genv.Set("UNDER_TEST", "1") + for i := 7000; i <= 8000; i++ { + ports.Append(i) + } +} + func Test_GetUrl(t *testing.T) { p, _ := ports.PopRand() s := g.Server(p) diff --git a/net/gtcp/gtcp_unit_pkg_test.go b/net/gtcp/gtcp_z_unit_conn_pkg_test.go similarity index 100% rename from net/gtcp/gtcp_unit_pkg_test.go rename to net/gtcp/gtcp_z_unit_conn_pkg_test.go diff --git a/net/gtcp/gtcp_unit_pool_pkg_test.go b/net/gtcp/gtcp_z_unit_pool_pkg_test.go similarity index 100% rename from net/gtcp/gtcp_unit_pool_pkg_test.go rename to net/gtcp/gtcp_z_unit_pool_pkg_test.go diff --git a/net/gtcp/gtcp_unit_pool_test.go b/net/gtcp/gtcp_z_unit_pool_test.go similarity index 100% rename from net/gtcp/gtcp_unit_pool_test.go rename to net/gtcp/gtcp_z_unit_pool_test.go diff --git a/net/gtcp/gtcp_unit_init_test.go b/net/gtcp/gtcp_z_unit_test.go similarity index 100% rename from net/gtcp/gtcp_unit_init_test.go rename to net/gtcp/gtcp_z_unit_test.go diff --git a/net/gtrace/gtrace_unit_carrier_test.go b/net/gtrace/gtrace_z_unit_carrier_test.go similarity index 100% rename from net/gtrace/gtrace_unit_carrier_test.go rename to net/gtrace/gtrace_z_unit_carrier_test.go diff --git a/net/gudp/gudp_unit_init_test.go b/net/gudp/gudp_unit_init_test.go deleted file mode 100644 index bee30f1b6..000000000 --- a/net/gudp/gudp_unit_init_test.go +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright GoFrame Author(https://goframe.org). All Rights Reserved. -// -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, -// You can obtain one at https://github.com/gogf/gf. - -package gudp_test - -import ( - "github.com/gogf/gf/v2/container/garray" -) - -var ( - ports = garray.NewIntArray(true) -) - -func init() { - for i := 9000; i <= 10000; i++ { - ports.Append(i) - } -} diff --git a/net/gudp/gudp_unit_basic_test.go b/net/gudp/gudp_z_unit_test.go similarity index 94% rename from net/gudp/gudp_unit_basic_test.go rename to net/gudp/gudp_z_unit_test.go index f611bb6ab..f9eca3157 100644 --- a/net/gudp/gudp_unit_basic_test.go +++ b/net/gudp/gudp_z_unit_test.go @@ -12,12 +12,23 @@ import ( "testing" "time" + "github.com/gogf/gf/v2/container/garray" "github.com/gogf/gf/v2/net/gudp" "github.com/gogf/gf/v2/os/glog" "github.com/gogf/gf/v2/test/gtest" "github.com/gogf/gf/v2/util/gconv" ) +var ( + ports = garray.NewIntArray(true) +) + +func init() { + for i := 9000; i <= 10000; i++ { + ports.Append(i) + } +} + func Test_Basic(t *testing.T) { var ( ctx = context.TODO() diff --git a/os/gbuild/gbuild_test.go b/os/gbuild/gbuild_z_unit_test.go similarity index 100% rename from os/gbuild/gbuild_test.go rename to os/gbuild/gbuild_z_unit_test.go diff --git a/os/gcache/gcache_z_unit_basic_test.go b/os/gcache/gcache_z_unit_test.go similarity index 100% rename from os/gcache/gcache_z_unit_basic_test.go rename to os/gcache/gcache_z_unit_test.go diff --git a/os/gcfg/gcfg_z_init_test.go b/os/gcfg/gcfg_z_unit_test.go similarity index 100% rename from os/gcfg/gcfg_z_init_test.go rename to os/gcfg/gcfg_z_unit_test.go diff --git a/os/gcmd/gcmd_z_unit_default_test.go b/os/gcmd/gcmd_z_unit_test.go similarity index 100% rename from os/gcmd/gcmd_z_unit_default_test.go rename to os/gcmd/gcmd_z_unit_test.go diff --git a/os/gcron/gcron_unit_2_test.go b/os/gcron/gcron_z_unit_entry_test.go similarity index 100% rename from os/gcron/gcron_unit_2_test.go rename to os/gcron/gcron_z_unit_entry_test.go diff --git a/os/gcron/gcron_unit_1_test.go b/os/gcron/gcron_z_unit_test.go similarity index 100% rename from os/gcron/gcron_unit_1_test.go rename to os/gcron/gcron_z_unit_test.go diff --git a/os/gctx/gctx_test.go b/os/gctx/gctx_z_unit_test.go similarity index 100% rename from os/gctx/gctx_test.go rename to os/gctx/gctx_z_unit_test.go diff --git a/os/genv/genv_test.go b/os/genv/genv_z_unit_test.go similarity index 100% rename from os/genv/genv_test.go rename to os/genv/genv_z_unit_test.go diff --git a/os/gfile/gfile_z_readline_test.go b/os/gfile/gfile_z_readline_test.go deleted file mode 100644 index 1cc860ebd..000000000 --- a/os/gfile/gfile_z_readline_test.go +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright GoFrame Author(https://goframe.org). All Rights Reserved. -// -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, -// You can obtain one at https://github.com/gogf/gf. - -package gfile_test - -import ( - "testing" - - "github.com/gogf/gf/v2/debug/gdebug" - "github.com/gogf/gf/v2/errors/gerror" - "github.com/gogf/gf/v2/os/gfile" - "github.com/gogf/gf/v2/test/gtest" -) - -func Test_NotFound(t *testing.T) { - gtest.C(t, func(t *gtest.T) { - teatFile := gfile.Dir(gdebug.CallerFilePath()) + gfile.Separator + "testdata/readline/error.log" - callback := func(line string) error { - return nil - } - err := gfile.ReadLines(teatFile, callback) - t.AssertNE(err, nil) - }) -} - -func Test_ReadLines(t *testing.T) { - gtest.C(t, func(t *gtest.T) { - var ( - expectList = []string{"a", "b", "c", "d", "e"} - getList = make([]string, 0) - callback = func(line string) error { - getList = append(getList, line) - return nil - } - teatFile = gfile.Dir(gdebug.CallerFilePath()) + gfile.Separator + "testdata/readline/file.log" - ) - err := gfile.ReadLines(teatFile, callback) - t.AssertEQ(getList, expectList) - t.AssertEQ(err, nil) - }) -} - -func Test_ReadLines_Error(t *testing.T) { - gtest.C(t, func(t *gtest.T) { - var ( - callback = func(line string) error { - return gerror.New("custom error") - } - teatFile = gfile.Dir(gdebug.CallerFilePath()) + gfile.Separator + "testdata/readline/file.log" - ) - err := gfile.ReadLines(teatFile, callback) - t.AssertEQ(err.Error(), "custom error") - }) -} - -func Test_ReadLinesBytes(t *testing.T) { - gtest.C(t, func(t *gtest.T) { - var ( - expectList = [][]byte{[]byte("a"), []byte("b"), []byte("c"), []byte("d"), []byte("e")} - getList = make([][]byte, 0) - callback = func(line []byte) error { - getList = append(getList, line) - return nil - } - teatFile = gfile.Dir(gdebug.CallerFilePath()) + gfile.Separator + "testdata/readline/file.log" - ) - err := gfile.ReadLinesBytes(teatFile, callback) - t.AssertEQ(getList, expectList) - t.AssertEQ(err, nil) - }) -} - -func Test_ReadLinesBytes_Error(t *testing.T) { - gtest.C(t, func(t *gtest.T) { - var ( - callback = func(line []byte) error { - return gerror.New("custom error") - } - teatFile = gfile.Dir(gdebug.CallerFilePath()) + gfile.Separator + "testdata/readline/file.log" - ) - err := gfile.ReadLinesBytes(teatFile, callback) - t.AssertEQ(err.Error(), "custom error") - }) -} diff --git a/os/gfile/gfile_z_cache_test.go b/os/gfile/gfile_z_unit_cache_test.go similarity index 100% rename from os/gfile/gfile_z_cache_test.go rename to os/gfile/gfile_z_unit_cache_test.go diff --git a/os/gfile/gfile_z_contents_test.go b/os/gfile/gfile_z_unit_contents_test.go similarity index 77% rename from os/gfile/gfile_z_contents_test.go rename to os/gfile/gfile_z_unit_contents_test.go index e95f0c68f..bd972d523 100644 --- a/os/gfile/gfile_z_contents_test.go +++ b/os/gfile/gfile_z_unit_contents_test.go @@ -13,6 +13,8 @@ import ( "strings" "testing" + "github.com/gogf/gf/v2/debug/gdebug" + "github.com/gogf/gf/v2/errors/gerror" "github.com/gogf/gf/v2/os/gfile" "github.com/gogf/gf/v2/test/gtest" "github.com/gogf/gf/v2/text/gstr" @@ -326,3 +328,74 @@ func Test_Home(t *testing.T) { t.AssertNE(reads, "") }) } + +func Test_NotFound(t *testing.T) { + gtest.C(t, func(t *gtest.T) { + teatFile := gfile.Dir(gdebug.CallerFilePath()) + gfile.Separator + "testdata/readline/error.log" + callback := func(line string) error { + return nil + } + err := gfile.ReadLines(teatFile, callback) + t.AssertNE(err, nil) + }) +} + +func Test_ReadLines(t *testing.T) { + gtest.C(t, func(t *gtest.T) { + var ( + expectList = []string{"a", "b", "c", "d", "e"} + getList = make([]string, 0) + callback = func(line string) error { + getList = append(getList, line) + return nil + } + teatFile = gfile.Dir(gdebug.CallerFilePath()) + gfile.Separator + "testdata/readline/file.log" + ) + err := gfile.ReadLines(teatFile, callback) + t.AssertEQ(getList, expectList) + t.AssertEQ(err, nil) + }) +} + +func Test_ReadLines_Error(t *testing.T) { + gtest.C(t, func(t *gtest.T) { + var ( + callback = func(line string) error { + return gerror.New("custom error") + } + teatFile = gfile.Dir(gdebug.CallerFilePath()) + gfile.Separator + "testdata/readline/file.log" + ) + err := gfile.ReadLines(teatFile, callback) + t.AssertEQ(err.Error(), "custom error") + }) +} + +func Test_ReadLinesBytes(t *testing.T) { + gtest.C(t, func(t *gtest.T) { + var ( + expectList = [][]byte{[]byte("a"), []byte("b"), []byte("c"), []byte("d"), []byte("e")} + getList = make([][]byte, 0) + callback = func(line []byte) error { + getList = append(getList, line) + return nil + } + teatFile = gfile.Dir(gdebug.CallerFilePath()) + gfile.Separator + "testdata/readline/file.log" + ) + err := gfile.ReadLinesBytes(teatFile, callback) + t.AssertEQ(getList, expectList) + t.AssertEQ(err, nil) + }) +} + +func Test_ReadLinesBytes_Error(t *testing.T) { + gtest.C(t, func(t *gtest.T) { + var ( + callback = func(line []byte) error { + return gerror.New("custom error") + } + teatFile = gfile.Dir(gdebug.CallerFilePath()) + gfile.Separator + "testdata/readline/file.log" + ) + err := gfile.ReadLinesBytes(teatFile, callback) + t.AssertEQ(err.Error(), "custom error") + }) +} diff --git a/os/gfile/gfile_z_copy_test.go b/os/gfile/gfile_z_unit_copy_test.go similarity index 100% rename from os/gfile/gfile_z_copy_test.go rename to os/gfile/gfile_z_unit_copy_test.go diff --git a/os/gfile/gfile_z_scan_test.go b/os/gfile/gfile_z_unit_scan_test.go similarity index 100% rename from os/gfile/gfile_z_scan_test.go rename to os/gfile/gfile_z_unit_scan_test.go diff --git a/os/gfile/gfile_z_search_test.go b/os/gfile/gfile_z_unit_search_test.go similarity index 100% rename from os/gfile/gfile_z_search_test.go rename to os/gfile/gfile_z_unit_search_test.go diff --git a/os/gfile/gfile_z_size_test.go b/os/gfile/gfile_z_unit_size_test.go similarity index 100% rename from os/gfile/gfile_z_size_test.go rename to os/gfile/gfile_z_unit_size_test.go diff --git a/os/gfile/gfile_z_test.go b/os/gfile/gfile_z_unit_test.go similarity index 100% rename from os/gfile/gfile_z_test.go rename to os/gfile/gfile_z_unit_test.go diff --git a/os/gfile/gfile_z_time_test.go b/os/gfile/gfile_z_unit_time_test.go similarity index 100% rename from os/gfile/gfile_z_time_test.go rename to os/gfile/gfile_z_unit_time_test.go diff --git a/os/gfpool/gfpool_z_unit_concurrent_test.go b/os/gfpool/gfpool_z_unit_concurrent_test.go deleted file mode 100644 index 646293e09..000000000 --- a/os/gfpool/gfpool_z_unit_concurrent_test.go +++ /dev/null @@ -1,196 +0,0 @@ -// Copyright GoFrame Author(https://goframe.org). All Rights Reserved. -// -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, -// You can obtain one at https://github.com/gogf/gf. - -package gfpool_test - -import ( - "os" - "testing" - - "github.com/gogf/gf/v2/os/gfile" - "github.com/gogf/gf/v2/os/gfpool" - "github.com/gogf/gf/v2/os/gtime" - "github.com/gogf/gf/v2/test/gtest" - "github.com/gogf/gf/v2/text/gstr" -) - -func Test_ConcurrentOS(t *testing.T) { - gtest.C(t, func(t *gtest.T) { - path := gfile.TempDir(gtime.TimestampNanoStr()) - defer gfile.Remove(path) - f1, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666) - t.Assert(err, nil) - defer f1.Close() - - f2, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666) - t.Assert(err, nil) - defer f2.Close() - - for i := 0; i < 100; i++ { - _, err = f1.Write([]byte("@1234567890#")) - t.Assert(err, nil) - } - for i := 0; i < 100; i++ { - _, err = f2.Write([]byte("@1234567890#")) - t.Assert(err, nil) - } - - for i := 0; i < 1000; i++ { - _, err = f1.Write([]byte("@1234567890#")) - t.Assert(err, nil) - } - for i := 0; i < 1000; i++ { - _, err = f2.Write([]byte("@1234567890#")) - t.Assert(err, nil) - } - t.Assert(gstr.Count(gfile.GetContents(path), "@1234567890#"), 2200) - }) - - gtest.C(t, func(t *gtest.T) { - path := gfile.TempDir(gtime.TimestampNanoStr()) - defer gfile.Remove(path) - f1, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666) - t.Assert(err, nil) - defer f1.Close() - - f2, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666) - t.Assert(err, nil) - defer f2.Close() - - for i := 0; i < 1000; i++ { - _, err = f1.Write([]byte("@1234567890#")) - t.Assert(err, nil) - } - for i := 0; i < 1000; i++ { - _, err = f2.Write([]byte("@1234567890#")) - t.Assert(err, nil) - } - t.Assert(gstr.Count(gfile.GetContents(path), "@1234567890#"), 2000) - }) - gtest.C(t, func(t *gtest.T) { - path := gfile.TempDir(gtime.TimestampNanoStr()) - defer gfile.Remove(path) - f1, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666) - t.Assert(err, nil) - defer f1.Close() - - f2, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666) - t.Assert(err, nil) - defer f2.Close() - - s1 := "" - for i := 0; i < 1000; i++ { - s1 += "@1234567890#" - } - _, err = f2.Write([]byte(s1)) - t.Assert(err, nil) - - s2 := "" - for i := 0; i < 1000; i++ { - s2 += "@1234567890#" - } - _, err = f2.Write([]byte(s2)) - t.Assert(err, nil) - - t.Assert(gstr.Count(gfile.GetContents(path), "@1234567890#"), 2000) - }) - // DATA RACE - // gtest.C(t, func(t *gtest.T) { - // path := gfile.TempDir(gtime.TimestampNanoStr()) - // defer gfile.Remove(path) - // f1, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666) - // t.Assert(err, nil) - // defer f1.Close() - // - // f2, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666) - // t.Assert(err, nil) - // defer f2.Close() - // - // wg := sync.WaitGroup{} - // ch := make(chan struct{}) - // for i := 0; i < 1000; i++ { - // wg.Add(1) - // go func() { - // defer wg.Done() - // <-ch - // _, err = f1.Write([]byte("@1234567890#")) - // t.Assert(err, nil) - // }() - // } - // for i := 0; i < 1000; i++ { - // wg.Add(1) - // go func() { - // defer wg.Done() - // <-ch - // _, err = f2.Write([]byte("@1234567890#")) - // t.Assert(err, nil) - // }() - // } - // close(ch) - // wg.Wait() - // t.Assert(gstr.Count(gfile.GetContents(path), "@1234567890#"), 2000) - // }) -} - -func Test_ConcurrentGFPool(t *testing.T) { - gtest.C(t, func(t *gtest.T) { - path := gfile.TempDir(gtime.TimestampNanoStr()) - defer gfile.Remove(path) - f1, err := gfpool.Open(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666) - t.Assert(err, nil) - defer f1.Close() - - f2, err := gfpool.Open(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666) - t.Assert(err, nil) - defer f2.Close() - - for i := 0; i < 1000; i++ { - _, err = f1.Write([]byte("@1234567890#")) - t.Assert(err, nil) - } - for i := 0; i < 1000; i++ { - _, err = f2.Write([]byte("@1234567890#")) - t.Assert(err, nil) - } - t.Assert(gstr.Count(gfile.GetContents(path), "@1234567890#"), 2000) - }) - // DATA RACE - // gtest.C(t, func(t *gtest.T) { - // path := gfile.TempDir(gtime.TimestampNanoStr()) - // defer gfile.Remove(path) - // f1, err := gfpool.Open(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666) - // t.Assert(err, nil) - // defer f1.Close() - // - // f2, err := gfpool.Open(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666) - // t.Assert(err, nil) - // defer f2.Close() - // - // wg := sync.WaitGroup{} - // ch := make(chan struct{}) - // for i := 0; i < 1000; i++ { - // wg.Add(1) - // go func() { - // defer wg.Done() - // <-ch - // _, err = f1.Write([]byte("@1234567890#")) - // t.Assert(err, nil) - // }() - // } - // for i := 0; i < 1000; i++ { - // wg.Add(1) - // go func() { - // defer wg.Done() - // <-ch - // _, err = f2.Write([]byte("@1234567890#")) - // t.Assert(err, nil) - // }() - // } - // close(ch) - // wg.Wait() - // t.Assert(gstr.Count(gfile.GetContents(path), "@1234567890#"), 2000) - // }) -} diff --git a/os/gfpool/gfpool_z_unit_test.go b/os/gfpool/gfpool_z_unit_test.go index 51a0252b3..87e12a461 100644 --- a/os/gfpool/gfpool_z_unit_test.go +++ b/os/gfpool/gfpool_z_unit_test.go @@ -15,7 +15,9 @@ import ( "github.com/gogf/gf/v2/os/gfile" "github.com/gogf/gf/v2/os/gfpool" "github.com/gogf/gf/v2/os/glog" + "github.com/gogf/gf/v2/os/gtime" "github.com/gogf/gf/v2/test/gtest" + "github.com/gogf/gf/v2/text/gstr" ) // TestOpen test open file cache @@ -142,3 +144,181 @@ func stop(testFile string) { } } } + +func Test_ConcurrentOS(t *testing.T) { + gtest.C(t, func(t *gtest.T) { + path := gfile.TempDir(gtime.TimestampNanoStr()) + defer gfile.Remove(path) + f1, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666) + t.Assert(err, nil) + defer f1.Close() + + f2, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666) + t.Assert(err, nil) + defer f2.Close() + + for i := 0; i < 100; i++ { + _, err = f1.Write([]byte("@1234567890#")) + t.Assert(err, nil) + } + for i := 0; i < 100; i++ { + _, err = f2.Write([]byte("@1234567890#")) + t.Assert(err, nil) + } + + for i := 0; i < 1000; i++ { + _, err = f1.Write([]byte("@1234567890#")) + t.Assert(err, nil) + } + for i := 0; i < 1000; i++ { + _, err = f2.Write([]byte("@1234567890#")) + t.Assert(err, nil) + } + t.Assert(gstr.Count(gfile.GetContents(path), "@1234567890#"), 2200) + }) + + gtest.C(t, func(t *gtest.T) { + path := gfile.TempDir(gtime.TimestampNanoStr()) + defer gfile.Remove(path) + f1, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666) + t.Assert(err, nil) + defer f1.Close() + + f2, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666) + t.Assert(err, nil) + defer f2.Close() + + for i := 0; i < 1000; i++ { + _, err = f1.Write([]byte("@1234567890#")) + t.Assert(err, nil) + } + for i := 0; i < 1000; i++ { + _, err = f2.Write([]byte("@1234567890#")) + t.Assert(err, nil) + } + t.Assert(gstr.Count(gfile.GetContents(path), "@1234567890#"), 2000) + }) + gtest.C(t, func(t *gtest.T) { + path := gfile.TempDir(gtime.TimestampNanoStr()) + defer gfile.Remove(path) + f1, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666) + t.Assert(err, nil) + defer f1.Close() + + f2, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666) + t.Assert(err, nil) + defer f2.Close() + + s1 := "" + for i := 0; i < 1000; i++ { + s1 += "@1234567890#" + } + _, err = f2.Write([]byte(s1)) + t.Assert(err, nil) + + s2 := "" + for i := 0; i < 1000; i++ { + s2 += "@1234567890#" + } + _, err = f2.Write([]byte(s2)) + t.Assert(err, nil) + + t.Assert(gstr.Count(gfile.GetContents(path), "@1234567890#"), 2000) + }) + // DATA RACE + // gtest.C(t, func(t *gtest.T) { + // path := gfile.TempDir(gtime.TimestampNanoStr()) + // defer gfile.Remove(path) + // f1, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666) + // t.Assert(err, nil) + // defer f1.Close() + // + // f2, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666) + // t.Assert(err, nil) + // defer f2.Close() + // + // wg := sync.WaitGroup{} + // ch := make(chan struct{}) + // for i := 0; i < 1000; i++ { + // wg.Add(1) + // go func() { + // defer wg.Done() + // <-ch + // _, err = f1.Write([]byte("@1234567890#")) + // t.Assert(err, nil) + // }() + // } + // for i := 0; i < 1000; i++ { + // wg.Add(1) + // go func() { + // defer wg.Done() + // <-ch + // _, err = f2.Write([]byte("@1234567890#")) + // t.Assert(err, nil) + // }() + // } + // close(ch) + // wg.Wait() + // t.Assert(gstr.Count(gfile.GetContents(path), "@1234567890#"), 2000) + // }) +} + +func Test_ConcurrentGFPool(t *testing.T) { + gtest.C(t, func(t *gtest.T) { + path := gfile.TempDir(gtime.TimestampNanoStr()) + defer gfile.Remove(path) + f1, err := gfpool.Open(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666) + t.Assert(err, nil) + defer f1.Close() + + f2, err := gfpool.Open(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666) + t.Assert(err, nil) + defer f2.Close() + + for i := 0; i < 1000; i++ { + _, err = f1.Write([]byte("@1234567890#")) + t.Assert(err, nil) + } + for i := 0; i < 1000; i++ { + _, err = f2.Write([]byte("@1234567890#")) + t.Assert(err, nil) + } + t.Assert(gstr.Count(gfile.GetContents(path), "@1234567890#"), 2000) + }) + // DATA RACE + // gtest.C(t, func(t *gtest.T) { + // path := gfile.TempDir(gtime.TimestampNanoStr()) + // defer gfile.Remove(path) + // f1, err := gfpool.Open(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666) + // t.Assert(err, nil) + // defer f1.Close() + // + // f2, err := gfpool.Open(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666) + // t.Assert(err, nil) + // defer f2.Close() + // + // wg := sync.WaitGroup{} + // ch := make(chan struct{}) + // for i := 0; i < 1000; i++ { + // wg.Add(1) + // go func() { + // defer wg.Done() + // <-ch + // _, err = f1.Write([]byte("@1234567890#")) + // t.Assert(err, nil) + // }() + // } + // for i := 0; i < 1000; i++ { + // wg.Add(1) + // go func() { + // defer wg.Done() + // <-ch + // _, err = f2.Write([]byte("@1234567890#")) + // t.Assert(err, nil) + // }() + // } + // close(ch) + // wg.Wait() + // t.Assert(gstr.Count(gfile.GetContents(path), "@1234567890#"), 2000) + // }) +} diff --git a/os/glog/glog_z_unit_concurrent_test.go b/os/glog/glog_z_unit_concurrent_test.go deleted file mode 100644 index a0d230dc1..000000000 --- a/os/glog/glog_z_unit_concurrent_test.go +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright GoFrame Author(https://goframe.org). All Rights Reserved. -// -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, -// You can obtain one at https://github.com/gogf/gf. - -package glog_test - -import ( - "sync" - "testing" - - "github.com/gogf/gf/v2/os/gfile" - "github.com/gogf/gf/v2/os/glog" - "github.com/gogf/gf/v2/os/gtime" - "github.com/gogf/gf/v2/test/gtest" - "github.com/gogf/gf/v2/text/gstr" -) - -func Test_Concurrent(t *testing.T) { - gtest.C(t, func(t *gtest.T) { - c := 1000 - l := glog.New() - s := "@1234567890#" - f := "test.log" - p := gfile.TempDir(gtime.TimestampNanoStr()) - t.Assert(l.SetPath(p), nil) - defer gfile.Remove(p) - wg := sync.WaitGroup{} - ch := make(chan struct{}) - for i := 0; i < c; i++ { - wg.Add(1) - go func() { - defer wg.Done() - <-ch - l.File(f).Stdout(false).Print(ctx, s) - }() - } - close(ch) - wg.Wait() - content := gfile.GetContents(gfile.Join(p, f)) - t.Assert(gstr.Count(content, s), c) - }) -} diff --git a/os/glog/glog_z_unit_basic_test.go b/os/glog/glog_z_unit_internal_test.go similarity index 55% rename from os/glog/glog_z_unit_basic_test.go rename to os/glog/glog_z_unit_internal_test.go index 30ef4a4b7..f712eaf4e 100644 --- a/os/glog/glog_z_unit_basic_test.go +++ b/os/glog/glog_z_unit_internal_test.go @@ -84,3 +84,48 @@ func Test_Error(t *testing.T) { t.Assert(gstr.Count(w.String(), "1 2 3"), 2) }) } + +func Test_LevelPrefix(t *testing.T) { + gtest.C(t, func(t *gtest.T) { + l := New() + t.Assert(l.GetLevelPrefix(LEVEL_DEBU), defaultLevelPrefixes[LEVEL_DEBU]) + t.Assert(l.GetLevelPrefix(LEVEL_INFO), defaultLevelPrefixes[LEVEL_INFO]) + t.Assert(l.GetLevelPrefix(LEVEL_NOTI), defaultLevelPrefixes[LEVEL_NOTI]) + t.Assert(l.GetLevelPrefix(LEVEL_WARN), defaultLevelPrefixes[LEVEL_WARN]) + t.Assert(l.GetLevelPrefix(LEVEL_ERRO), defaultLevelPrefixes[LEVEL_ERRO]) + t.Assert(l.GetLevelPrefix(LEVEL_CRIT), defaultLevelPrefixes[LEVEL_CRIT]) + l.SetLevelPrefix(LEVEL_DEBU, "debug") + t.Assert(l.GetLevelPrefix(LEVEL_DEBU), "debug") + l.SetLevelPrefixes(map[int]string{ + LEVEL_CRIT: "critical", + }) + t.Assert(l.GetLevelPrefix(LEVEL_DEBU), "debug") + t.Assert(l.GetLevelPrefix(LEVEL_INFO), defaultLevelPrefixes[LEVEL_INFO]) + t.Assert(l.GetLevelPrefix(LEVEL_NOTI), defaultLevelPrefixes[LEVEL_NOTI]) + t.Assert(l.GetLevelPrefix(LEVEL_WARN), defaultLevelPrefixes[LEVEL_WARN]) + t.Assert(l.GetLevelPrefix(LEVEL_ERRO), defaultLevelPrefixes[LEVEL_ERRO]) + t.Assert(l.GetLevelPrefix(LEVEL_CRIT), "critical") + }) + gtest.C(t, func(t *gtest.T) { + buffer := bytes.NewBuffer(nil) + l := New() + l.SetWriter(buffer) + l.Debug(ctx, "test1") + t.Assert(gstr.Contains(buffer.String(), defaultLevelPrefixes[LEVEL_DEBU]), true) + + buffer.Reset() + + l.SetLevelPrefix(LEVEL_DEBU, "debug") + l.Debug(ctx, "test2") + t.Assert(gstr.Contains(buffer.String(), defaultLevelPrefixes[LEVEL_DEBU]), false) + t.Assert(gstr.Contains(buffer.String(), "debug"), true) + + buffer.Reset() + l.SetLevelPrefixes(map[int]string{ + LEVEL_ERRO: "error", + }) + l.Error(ctx, "test3") + t.Assert(gstr.Contains(buffer.String(), defaultLevelPrefixes[LEVEL_ERRO]), false) + t.Assert(gstr.Contains(buffer.String(), "error"), true) + }) +} diff --git a/os/glog/glog_z_unit_level_test.go b/os/glog/glog_z_unit_level_test.go deleted file mode 100644 index c5c9b68aa..000000000 --- a/os/glog/glog_z_unit_level_test.go +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright GoFrame Author(https://goframe.org). All Rights Reserved. -// -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, -// You can obtain one at https://github.com/gogf/gf. - -package glog - -import ( - "bytes" - "testing" - - "github.com/gogf/gf/v2/test/gtest" - "github.com/gogf/gf/v2/text/gstr" -) - -func Test_LevelPrefix(t *testing.T) { - gtest.C(t, func(t *gtest.T) { - l := New() - t.Assert(l.GetLevelPrefix(LEVEL_DEBU), defaultLevelPrefixes[LEVEL_DEBU]) - t.Assert(l.GetLevelPrefix(LEVEL_INFO), defaultLevelPrefixes[LEVEL_INFO]) - t.Assert(l.GetLevelPrefix(LEVEL_NOTI), defaultLevelPrefixes[LEVEL_NOTI]) - t.Assert(l.GetLevelPrefix(LEVEL_WARN), defaultLevelPrefixes[LEVEL_WARN]) - t.Assert(l.GetLevelPrefix(LEVEL_ERRO), defaultLevelPrefixes[LEVEL_ERRO]) - t.Assert(l.GetLevelPrefix(LEVEL_CRIT), defaultLevelPrefixes[LEVEL_CRIT]) - l.SetLevelPrefix(LEVEL_DEBU, "debug") - t.Assert(l.GetLevelPrefix(LEVEL_DEBU), "debug") - l.SetLevelPrefixes(map[int]string{ - LEVEL_CRIT: "critical", - }) - t.Assert(l.GetLevelPrefix(LEVEL_DEBU), "debug") - t.Assert(l.GetLevelPrefix(LEVEL_INFO), defaultLevelPrefixes[LEVEL_INFO]) - t.Assert(l.GetLevelPrefix(LEVEL_NOTI), defaultLevelPrefixes[LEVEL_NOTI]) - t.Assert(l.GetLevelPrefix(LEVEL_WARN), defaultLevelPrefixes[LEVEL_WARN]) - t.Assert(l.GetLevelPrefix(LEVEL_ERRO), defaultLevelPrefixes[LEVEL_ERRO]) - t.Assert(l.GetLevelPrefix(LEVEL_CRIT), "critical") - }) - gtest.C(t, func(t *gtest.T) { - buffer := bytes.NewBuffer(nil) - l := New() - l.SetWriter(buffer) - l.Debug(ctx, "test1") - t.Assert(gstr.Contains(buffer.String(), defaultLevelPrefixes[LEVEL_DEBU]), true) - - buffer.Reset() - - l.SetLevelPrefix(LEVEL_DEBU, "debug") - l.Debug(ctx, "test2") - t.Assert(gstr.Contains(buffer.String(), defaultLevelPrefixes[LEVEL_DEBU]), false) - t.Assert(gstr.Contains(buffer.String(), "debug"), true) - - buffer.Reset() - l.SetLevelPrefixes(map[int]string{ - LEVEL_ERRO: "error", - }) - l.Error(ctx, "test3") - t.Assert(gstr.Contains(buffer.String(), defaultLevelPrefixes[LEVEL_ERRO]), false) - t.Assert(gstr.Contains(buffer.String(), "error"), true) - }) -} diff --git a/os/glog/glog_z_unit_chaining_test.go b/os/glog/glog_z_unit_logger_chaining_test.go similarity index 100% rename from os/glog/glog_z_unit_chaining_test.go rename to os/glog/glog_z_unit_logger_chaining_test.go diff --git a/os/glog/glog_z_unit_handler_test.go b/os/glog/glog_z_unit_logger_handler_test.go similarity index 100% rename from os/glog/glog_z_unit_handler_test.go rename to os/glog/glog_z_unit_logger_handler_test.go diff --git a/os/glog/glog_z_unit_rotate_test.go b/os/glog/glog_z_unit_logger_rotate_test.go similarity index 100% rename from os/glog/glog_z_unit_rotate_test.go rename to os/glog/glog_z_unit_logger_rotate_test.go diff --git a/os/glog/glog_z_unit_ctx_test.go b/os/glog/glog_z_unit_test.go similarity index 74% rename from os/glog/glog_z_unit_ctx_test.go rename to os/glog/glog_z_unit_test.go index a760cd331..054e75a44 100644 --- a/os/glog/glog_z_unit_ctx_test.go +++ b/os/glog/glog_z_unit_test.go @@ -9,11 +9,14 @@ package glog_test import ( "bytes" "context" + "sync" "testing" "github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/os/gctx" + "github.com/gogf/gf/v2/os/gfile" "github.com/gogf/gf/v2/os/glog" + "github.com/gogf/gf/v2/os/gtime" "github.com/gogf/gf/v2/test/gtest" "github.com/gogf/gf/v2/text/gstr" ) @@ -61,3 +64,29 @@ func Test_Ctx_CtxKey(t *testing.T) { t.Assert(gstr.Count(w.String(), "1 2 3"), 1) }) } + +func Test_Concurrent(t *testing.T) { + gtest.C(t, func(t *gtest.T) { + c := 1000 + l := glog.New() + s := "@1234567890#" + f := "test.log" + p := gfile.TempDir(gtime.TimestampNanoStr()) + t.Assert(l.SetPath(p), nil) + defer gfile.Remove(p) + wg := sync.WaitGroup{} + ch := make(chan struct{}) + for i := 0; i < c; i++ { + wg.Add(1) + go func() { + defer wg.Done() + <-ch + l.File(f).Stdout(false).Print(ctx, s) + }() + } + close(ch) + wg.Wait() + content := gfile.GetContents(gfile.Join(p, f)) + t.Assert(gstr.Count(content, s), c) + }) +} diff --git a/os/gmlock/gmlock_unit_lock_test.go b/os/gmlock/gmlock_unit_lock_test.go deleted file mode 100644 index d738d603b..000000000 --- a/os/gmlock/gmlock_unit_lock_test.go +++ /dev/null @@ -1,205 +0,0 @@ -// Copyright GoFrame Author(https://goframe.org). All Rights Reserved. -// -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, -// You can obtain one at https://github.com/gogf/gf. - -package gmlock_test - -import ( - "sync" - "testing" - "time" - - "github.com/gogf/gf/v2/container/garray" - "github.com/gogf/gf/v2/os/gmlock" - "github.com/gogf/gf/v2/test/gtest" -) - -func Test_Locker_Lock(t *testing.T) { - gtest.C(t, func(t *gtest.T) { - key := "testLock" - array := garray.New(true) - go func() { - gmlock.Lock(key) - array.Append(1) - time.Sleep(300 * time.Millisecond) - gmlock.Unlock(key) - }() - go func() { - time.Sleep(100 * time.Millisecond) - gmlock.Lock(key) - array.Append(1) - gmlock.Unlock(key) - }() - time.Sleep(100 * time.Millisecond) - t.Assert(array.Len(), 1) - time.Sleep(100 * time.Millisecond) - t.Assert(array.Len(), 1) - time.Sleep(200 * time.Millisecond) - t.Assert(array.Len(), 2) - gmlock.Remove(key) - }) - - gtest.C(t, func(t *gtest.T) { - key := "testLock" - array := garray.New(true) - lock := gmlock.New() - go func() { - lock.Lock(key) - array.Append(1) - time.Sleep(300 * time.Millisecond) - lock.Unlock(key) - }() - go func() { - time.Sleep(100 * time.Millisecond) - lock.Lock(key) - array.Append(1) - lock.Unlock(key) - }() - time.Sleep(100 * time.Millisecond) - t.Assert(array.Len(), 1) - time.Sleep(100 * time.Millisecond) - t.Assert(array.Len(), 1) - time.Sleep(200 * time.Millisecond) - t.Assert(array.Len(), 2) - lock.Clear() - }) - -} - -func Test_Locker_TryLock(t *testing.T) { - gtest.C(t, func(t *gtest.T) { - key := "testTryLock" - array := garray.New(true) - go func() { - gmlock.Lock(key) - array.Append(1) - time.Sleep(300 * time.Millisecond) - gmlock.Unlock(key) - }() - go func() { - time.Sleep(150 * time.Millisecond) - if gmlock.TryLock(key) { - array.Append(1) - gmlock.Unlock(key) - } - }() - go func() { - time.Sleep(400 * time.Millisecond) - if gmlock.TryLock(key) { - array.Append(1) - gmlock.Unlock(key) - } - }() - time.Sleep(100 * time.Millisecond) - t.Assert(array.Len(), 1) - time.Sleep(100 * time.Millisecond) - t.Assert(array.Len(), 1) - time.Sleep(300 * time.Millisecond) - t.Assert(array.Len(), 2) - }) - -} - -func Test_Locker_LockFunc(t *testing.T) { - //no expire - gtest.C(t, func(t *gtest.T) { - key := "testLockFunc" - array := garray.New(true) - go func() { - gmlock.LockFunc(key, func() { - array.Append(1) - time.Sleep(300 * time.Millisecond) - }) // - }() - go func() { - time.Sleep(100 * time.Millisecond) - gmlock.LockFunc(key, func() { - array.Append(1) - }) - }() - time.Sleep(100 * time.Millisecond) - t.Assert(array.Len(), 1) - time.Sleep(100 * time.Millisecond) - t.Assert(array.Len(), 1) // - time.Sleep(200 * time.Millisecond) - t.Assert(array.Len(), 2) - }) -} -func Test_Locker_TryLockFunc(t *testing.T) { - //no expire - gtest.C(t, func(t *gtest.T) { - key := "testTryLockFunc" - array := garray.New(true) - go func() { - gmlock.TryLockFunc(key, func() { - array.Append(1) - time.Sleep(200 * time.Millisecond) - }) - }() - go func() { - time.Sleep(100 * time.Millisecond) - gmlock.TryLockFunc(key, func() { - array.Append(1) - }) - }() - go func() { - time.Sleep(300 * time.Millisecond) - gmlock.TryLockFunc(key, func() { - array.Append(1) - }) - }() - time.Sleep(150 * time.Millisecond) - t.Assert(array.Len(), 1) - time.Sleep(400 * time.Millisecond) - t.Assert(array.Len(), 2) - }) -} - -func Test_Multiple_Goroutine(t *testing.T) { - gtest.C(t, func(t *gtest.T) { - ch := make(chan struct{}, 0) - num := 1000 - wait := sync.WaitGroup{} - wait.Add(num) - for i := 0; i < num; i++ { - go func() { - defer wait.Done() - <-ch - gmlock.Lock("test") - defer gmlock.Unlock("test") - time.Sleep(time.Millisecond) - }() - } - close(ch) - wait.Wait() - }) - - gtest.C(t, func(t *gtest.T) { - ch := make(chan struct{}, 0) - num := 100 - wait := sync.WaitGroup{} - wait.Add(num * 2) - for i := 0; i < num; i++ { - go func() { - defer wait.Done() - <-ch - gmlock.Lock("test") - defer gmlock.Unlock("test") - time.Sleep(time.Millisecond) - }() - } - for i := 0; i < num; i++ { - go func() { - defer wait.Done() - <-ch - gmlock.RLock("test") - defer gmlock.RUnlock("test") - time.Sleep(time.Millisecond) - }() - } - close(ch) - wait.Wait() - }) -} diff --git a/os/gmlock/gmlock_unit_rlock_test.go b/os/gmlock/gmlock_z_unit_test.go similarity index 61% rename from os/gmlock/gmlock_unit_rlock_test.go rename to os/gmlock/gmlock_z_unit_test.go index 75cf0e5ba..9d2a08714 100644 --- a/os/gmlock/gmlock_unit_rlock_test.go +++ b/os/gmlock/gmlock_z_unit_test.go @@ -7,6 +7,7 @@ package gmlock_test import ( + "sync" "testing" "time" @@ -15,6 +16,195 @@ import ( "github.com/gogf/gf/v2/test/gtest" ) +func Test_Locker_Lock(t *testing.T) { + gtest.C(t, func(t *gtest.T) { + key := "testLock" + array := garray.New(true) + go func() { + gmlock.Lock(key) + array.Append(1) + time.Sleep(300 * time.Millisecond) + gmlock.Unlock(key) + }() + go func() { + time.Sleep(100 * time.Millisecond) + gmlock.Lock(key) + array.Append(1) + gmlock.Unlock(key) + }() + time.Sleep(100 * time.Millisecond) + t.Assert(array.Len(), 1) + time.Sleep(100 * time.Millisecond) + t.Assert(array.Len(), 1) + time.Sleep(200 * time.Millisecond) + t.Assert(array.Len(), 2) + gmlock.Remove(key) + }) + + gtest.C(t, func(t *gtest.T) { + key := "testLock" + array := garray.New(true) + lock := gmlock.New() + go func() { + lock.Lock(key) + array.Append(1) + time.Sleep(300 * time.Millisecond) + lock.Unlock(key) + }() + go func() { + time.Sleep(100 * time.Millisecond) + lock.Lock(key) + array.Append(1) + lock.Unlock(key) + }() + time.Sleep(100 * time.Millisecond) + t.Assert(array.Len(), 1) + time.Sleep(100 * time.Millisecond) + t.Assert(array.Len(), 1) + time.Sleep(200 * time.Millisecond) + t.Assert(array.Len(), 2) + lock.Clear() + }) + +} + +func Test_Locker_TryLock(t *testing.T) { + gtest.C(t, func(t *gtest.T) { + key := "testTryLock" + array := garray.New(true) + go func() { + gmlock.Lock(key) + array.Append(1) + time.Sleep(300 * time.Millisecond) + gmlock.Unlock(key) + }() + go func() { + time.Sleep(150 * time.Millisecond) + if gmlock.TryLock(key) { + array.Append(1) + gmlock.Unlock(key) + } + }() + go func() { + time.Sleep(400 * time.Millisecond) + if gmlock.TryLock(key) { + array.Append(1) + gmlock.Unlock(key) + } + }() + time.Sleep(100 * time.Millisecond) + t.Assert(array.Len(), 1) + time.Sleep(100 * time.Millisecond) + t.Assert(array.Len(), 1) + time.Sleep(300 * time.Millisecond) + t.Assert(array.Len(), 2) + }) + +} + +func Test_Locker_LockFunc(t *testing.T) { + //no expire + gtest.C(t, func(t *gtest.T) { + key := "testLockFunc" + array := garray.New(true) + go func() { + gmlock.LockFunc(key, func() { + array.Append(1) + time.Sleep(300 * time.Millisecond) + }) // + }() + go func() { + time.Sleep(100 * time.Millisecond) + gmlock.LockFunc(key, func() { + array.Append(1) + }) + }() + time.Sleep(100 * time.Millisecond) + t.Assert(array.Len(), 1) + time.Sleep(100 * time.Millisecond) + t.Assert(array.Len(), 1) // + time.Sleep(200 * time.Millisecond) + t.Assert(array.Len(), 2) + }) +} + +func Test_Locker_TryLockFunc(t *testing.T) { + //no expire + gtest.C(t, func(t *gtest.T) { + key := "testTryLockFunc" + array := garray.New(true) + go func() { + gmlock.TryLockFunc(key, func() { + array.Append(1) + time.Sleep(200 * time.Millisecond) + }) + }() + go func() { + time.Sleep(100 * time.Millisecond) + gmlock.TryLockFunc(key, func() { + array.Append(1) + }) + }() + go func() { + time.Sleep(300 * time.Millisecond) + gmlock.TryLockFunc(key, func() { + array.Append(1) + }) + }() + time.Sleep(150 * time.Millisecond) + t.Assert(array.Len(), 1) + time.Sleep(400 * time.Millisecond) + t.Assert(array.Len(), 2) + }) +} + +func Test_Multiple_Goroutine(t *testing.T) { + gtest.C(t, func(t *gtest.T) { + ch := make(chan struct{}, 0) + num := 1000 + wait := sync.WaitGroup{} + wait.Add(num) + for i := 0; i < num; i++ { + go func() { + defer wait.Done() + <-ch + gmlock.Lock("test") + defer gmlock.Unlock("test") + time.Sleep(time.Millisecond) + }() + } + close(ch) + wait.Wait() + }) + + gtest.C(t, func(t *gtest.T) { + ch := make(chan struct{}, 0) + num := 100 + wait := sync.WaitGroup{} + wait.Add(num * 2) + for i := 0; i < num; i++ { + go func() { + defer wait.Done() + <-ch + gmlock.Lock("test") + defer gmlock.Unlock("test") + time.Sleep(time.Millisecond) + }() + } + for i := 0; i < num; i++ { + go func() { + defer wait.Done() + <-ch + gmlock.RLock("test") + defer gmlock.RUnlock("test") + time.Sleep(time.Millisecond) + }() + } + close(ch) + wait.Wait() + }) +} + func Test_Locker_RLock(t *testing.T) { // RLock before Lock gtest.C(t, func(t *gtest.T) { diff --git a/os/gmutex/gmutex_bench_test.go b/os/gmutex/gmutex_z_bench_test.go similarity index 100% rename from os/gmutex/gmutex_bench_test.go rename to os/gmutex/gmutex_z_bench_test.go diff --git a/os/gmutex/gmutex_unit_test.go b/os/gmutex/gmutex_z_unit_test.go similarity index 100% rename from os/gmutex/gmutex_unit_test.go rename to os/gmutex/gmutex_z_unit_test.go diff --git a/os/gres/gres_z_unit_1_test.go b/os/gres/gres_z_unit_1_test.go deleted file mode 100644 index a0cdaeca4..000000000 --- a/os/gres/gres_z_unit_1_test.go +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright GoFrame Author(https://goframe.org). All Rights Reserved. -// -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, -// You can obtain one at https://github.com/gogf/gf. - -package gres_test - -import ( - "strings" - "testing" - - "github.com/gogf/gf/v2/debug/gdebug" - "github.com/gogf/gf/v2/os/gfile" - "github.com/gogf/gf/v2/os/gres" - "github.com/gogf/gf/v2/os/gtime" - "github.com/gogf/gf/v2/test/gtest" -) - -func Test_PackToGoFile(t *testing.T) { - gtest.C(t, func(t *gtest.T) { - srcPath := gdebug.TestDataPath("files") - goFilePath := gdebug.TestDataPath("testdata.go") - pkgName := "testdata" - err := gres.PackToGoFile(srcPath, goFilePath, pkgName) - t.Assert(err, nil) - }) -} - -func Test_Pack(t *testing.T) { - gtest.C(t, func(t *gtest.T) { - srcPath := gdebug.TestDataPath("files") - data, err := gres.Pack(srcPath) - t.Assert(err, nil) - - r := gres.New() - - err = r.Add(string(data)) - t.Assert(err, nil) - t.Assert(r.Contains("files/"), true) - }) -} - -func Test_PackToFile(t *testing.T) { - gtest.C(t, func(t *gtest.T) { - srcPath := gdebug.TestDataPath("files") - dstPath := gfile.TempDir(gtime.TimestampNanoStr()) - err := gres.PackToFile(srcPath, dstPath) - t.Assert(err, nil) - - defer gfile.Remove(dstPath) - - r := gres.New() - err = r.Load(dstPath) - t.Assert(err, nil) - t.Assert(r.Contains("files"), true) - }) -} - -func Test_PackMulti(t *testing.T) { - gtest.C(t, func(t *gtest.T) { - srcPath := gdebug.TestDataPath("files") - goFilePath := gdebug.TestDataPath("data/data.go") - pkgName := "data" - array, err := gfile.ScanDir(srcPath, "*", false) - t.Assert(err, nil) - err = gres.PackToGoFile(strings.Join(array, ","), goFilePath, pkgName) - t.Assert(err, nil) - }) -} - -func Test_PackWithPrefix1(t *testing.T) { - gtest.C(t, func(t *gtest.T) { - srcPath := gdebug.TestDataPath("files") - goFilePath := gfile.TempDir("testdata.go") - pkgName := "testdata" - err := gres.PackToGoFile(srcPath, goFilePath, pkgName, "www/gf-site/test") - t.Assert(err, nil) - }) -} - -func Test_PackWithPrefix2(t *testing.T) { - gtest.C(t, func(t *gtest.T) { - srcPath := gdebug.TestDataPath("files") - goFilePath := gfile.TempDir("testdata.go") - pkgName := "testdata" - err := gres.PackToGoFile(srcPath, goFilePath, pkgName, "/var/www/gf-site/test") - t.Assert(err, nil) - }) -} diff --git a/os/gres/gres_z_unit_2_test.go b/os/gres/gres_z_unit_test.go similarity index 62% rename from os/gres/gres_z_unit_2_test.go rename to os/gres/gres_z_unit_test.go index c95fe7f9c..06c61a1c6 100644 --- a/os/gres/gres_z_unit_2_test.go +++ b/os/gres/gres_z_unit_test.go @@ -7,14 +7,89 @@ package gres_test import ( + "strings" "testing" + "github.com/gogf/gf/v2/debug/gdebug" "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/os/gfile" "github.com/gogf/gf/v2/os/gres" - _ "github.com/gogf/gf/v2/os/gres/testdata/data" + "github.com/gogf/gf/v2/os/gtime" "github.com/gogf/gf/v2/test/gtest" ) +func Test_PackToGoFile(t *testing.T) { + gtest.C(t, func(t *gtest.T) { + srcPath := gdebug.TestDataPath("files") + goFilePath := gdebug.TestDataPath("testdata.go") + pkgName := "testdata" + err := gres.PackToGoFile(srcPath, goFilePath, pkgName) + t.Assert(err, nil) + }) +} + +func Test_Pack(t *testing.T) { + gtest.C(t, func(t *gtest.T) { + srcPath := gdebug.TestDataPath("files") + data, err := gres.Pack(srcPath) + t.Assert(err, nil) + + r := gres.New() + + err = r.Add(string(data)) + t.Assert(err, nil) + t.Assert(r.Contains("files/"), true) + }) +} + +func Test_PackToFile(t *testing.T) { + gtest.C(t, func(t *gtest.T) { + srcPath := gdebug.TestDataPath("files") + dstPath := gfile.TempDir(gtime.TimestampNanoStr()) + err := gres.PackToFile(srcPath, dstPath) + t.Assert(err, nil) + + defer gfile.Remove(dstPath) + + r := gres.New() + err = r.Load(dstPath) + t.Assert(err, nil) + t.Assert(r.Contains("files"), true) + }) +} + +func Test_PackMulti(t *testing.T) { + gtest.C(t, func(t *gtest.T) { + srcPath := gdebug.TestDataPath("files") + goFilePath := gdebug.TestDataPath("data/data.go") + pkgName := "data" + array, err := gfile.ScanDir(srcPath, "*", false) + t.Assert(err, nil) + err = gres.PackToGoFile(strings.Join(array, ","), goFilePath, pkgName) + t.Assert(err, nil) + }) +} + +func Test_PackWithPrefix1(t *testing.T) { + gtest.C(t, func(t *gtest.T) { + srcPath := gdebug.TestDataPath("files") + goFilePath := gfile.TempDir("testdata.go") + pkgName := "testdata" + err := gres.PackToGoFile(srcPath, goFilePath, pkgName, "www/gf-site/test") + t.Assert(err, nil) + }) +} + +func Test_PackWithPrefix2(t *testing.T) { + gtest.C(t, func(t *gtest.T) { + srcPath := gdebug.TestDataPath("files") + goFilePath := gfile.TempDir("testdata.go") + pkgName := "testdata" + err := gres.PackToGoFile(srcPath, goFilePath, pkgName, "/var/www/gf-site/test") + t.Assert(err, nil) + }) +} + func Test_Basic(t *testing.T) { gres.Dump() gtest.C(t, func(t *gtest.T) { diff --git a/os/grpool/grpool_bench_2_test.go b/os/grpool/grpool_bench_2_test.go deleted file mode 100644 index 1dc02e18f..000000000 --- a/os/grpool/grpool_bench_2_test.go +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright GoFrame Author(https://goframe.org). All Rights Reserved. -// -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, -// You can obtain one at https://github.com/gogf/gf. - -// go test *.go -bench=".*" -count=1 - -package grpool_test - -import ( - "testing" - - "github.com/gogf/gf/v2/os/grpool" -) - -var n = 500000 - -func BenchmarkGrpool2(b *testing.B) { - b.N = n - for i := 0; i < b.N; i++ { - grpool.Add(ctx, increment) - } -} - -func BenchmarkGoroutine2(b *testing.B) { - b.N = n - for i := 0; i < b.N; i++ { - go increment(ctx) - } -} diff --git a/os/grpool/grpool_bench_1_test.go b/os/grpool/grpool_z_bench_test.go similarity index 74% rename from os/grpool/grpool_bench_1_test.go rename to os/grpool/grpool_z_bench_test.go index 7c576da97..411afb14f 100644 --- a/os/grpool/grpool_bench_1_test.go +++ b/os/grpool/grpool_z_bench_test.go @@ -17,6 +17,7 @@ import ( var ( ctx = context.TODO() + n = 500000 ) func increment(ctx context.Context) { @@ -35,3 +36,17 @@ func BenchmarkGoroutine_1(b *testing.B) { go increment(ctx) } } + +func BenchmarkGrpool2(b *testing.B) { + b.N = n + for i := 0; i < b.N; i++ { + grpool.Add(ctx, increment) + } +} + +func BenchmarkGoroutine2(b *testing.B) { + b.N = n + for i := 0; i < b.N; i++ { + go increment(ctx) + } +} diff --git a/os/grpool/grpool_unit_test.go b/os/grpool/grpool_z_unit_test.go similarity index 100% rename from os/grpool/grpool_unit_test.go rename to os/grpool/grpool_z_unit_test.go diff --git a/os/gsession/gsession_unit_storage_file_test.go b/os/gsession/gsession_z_unit_storage_file_test.go similarity index 100% rename from os/gsession/gsession_unit_storage_file_test.go rename to os/gsession/gsession_z_unit_storage_file_test.go diff --git a/os/gsession/gsession_unit_storage_memory_test.go b/os/gsession/gsession_z_unit_storage_memory_test.go similarity index 100% rename from os/gsession/gsession_unit_storage_memory_test.go rename to os/gsession/gsession_z_unit_storage_memory_test.go diff --git a/os/gsession/gsession_unit_storage_redis_hashtable_test.go b/os/gsession/gsession_z_unit_storage_redis_hashtable_test.go similarity index 100% rename from os/gsession/gsession_unit_storage_redis_hashtable_test.go rename to os/gsession/gsession_z_unit_storage_redis_hashtable_test.go diff --git a/os/gsession/gsession_unit_storage_redis_test.go b/os/gsession/gsession_z_unit_storage_redis_test.go similarity index 100% rename from os/gsession/gsession_unit_storage_redis_test.go rename to os/gsession/gsession_z_unit_storage_redis_test.go diff --git a/os/gsession/gsession_unit_test.go b/os/gsession/gsession_z_unit_test.go similarity index 100% rename from os/gsession/gsession_unit_test.go rename to os/gsession/gsession_z_unit_test.go diff --git a/os/gspath/gspath_unit_test.go b/os/gspath/gspath_z_unit_test.go similarity index 100% rename from os/gspath/gspath_unit_test.go rename to os/gspath/gspath_z_unit_test.go diff --git a/os/gtime/gtime_z_unit_json_test.go b/os/gtime/gtime_z_unit_feature_json_test.go similarity index 100% rename from os/gtime/gtime_z_unit_json_test.go rename to os/gtime/gtime_z_unit_feature_json_test.go diff --git a/os/gtime/gtime_z_unit_sql_test.go b/os/gtime/gtime_z_unit_feature_sql_test.go similarity index 100% rename from os/gtime/gtime_z_unit_sql_test.go rename to os/gtime/gtime_z_unit_feature_sql_test.go diff --git a/os/gtime/gtime_z_unit_basic_test.go b/os/gtime/gtime_z_unit_test.go similarity index 100% rename from os/gtime/gtime_z_unit_basic_test.go rename to os/gtime/gtime_z_unit_test.go diff --git a/os/gtimer/gtimer_z_unit_timer_internal_test.go b/os/gtimer/gtimer_z_unit_internal_test.go similarity index 100% rename from os/gtimer/gtimer_z_unit_timer_internal_test.go rename to os/gtimer/gtimer_z_unit_internal_test.go diff --git a/os/gtimer/gtimer_z_unit_api_test.go b/os/gtimer/gtimer_z_unit_test.go similarity index 100% rename from os/gtimer/gtimer_z_unit_api_test.go rename to os/gtimer/gtimer_z_unit_test.go diff --git a/os/gview/gview_unit_config_test.go b/os/gview/gview_z_unit_config_test.go similarity index 100% rename from os/gview/gview_unit_config_test.go rename to os/gview/gview_z_unit_config_test.go diff --git a/os/gview/gview_unit_encode_test.go b/os/gview/gview_z_unit_feature_encode_test.go similarity index 100% rename from os/gview/gview_unit_encode_test.go rename to os/gview/gview_z_unit_feature_encode_test.go diff --git a/os/gview/gview_unit_i18n_test.go b/os/gview/gview_z_unit_i18n_test.go similarity index 100% rename from os/gview/gview_unit_i18n_test.go rename to os/gview/gview_z_unit_i18n_test.go diff --git a/os/gview/gview_unit_basic_test.go b/os/gview/gview_z_unit_test.go similarity index 100% rename from os/gview/gview_unit_basic_test.go rename to os/gview/gview_z_unit_test.go diff --git a/protocol/goai/goai_test.go b/protocol/goai/goai_z_unit_test.go similarity index 100% rename from protocol/goai/goai_test.go rename to protocol/goai/goai_z_unit_test.go diff --git a/util/gmeta/gmeta_bench_test.go b/util/gmeta/gmeta_z_bench_test.go similarity index 100% rename from util/gmeta/gmeta_bench_test.go rename to util/gmeta/gmeta_z_bench_test.go diff --git a/util/gmeta/gmeta_unit_test.go b/util/gmeta/gmeta_z_unit_test.go similarity index 100% rename from util/gmeta/gmeta_unit_test.go rename to util/gmeta/gmeta_z_unit_test.go diff --git a/util/gmode/gmode_test.go b/util/gmode/gmode_z_unit_test.go similarity index 100% rename from util/gmode/gmode_test.go rename to util/gmode/gmode_z_unit_test.go diff --git a/util/gpage/gpage_unit_test.go b/util/gpage/gpage_z_unit_test.go similarity index 100% rename from util/gpage/gpage_unit_test.go rename to util/gpage/gpage_z_unit_test.go diff --git a/util/gvalid/gvalid_z_unit_checkmap_test.go b/util/gvalid/gvalid_z_unit_feature_checkmap_test.go similarity index 98% rename from util/gvalid/gvalid_z_unit_checkmap_test.go rename to util/gvalid/gvalid_z_unit_feature_checkmap_test.go index 27a618a47..4f0849a76 100755 --- a/util/gvalid/gvalid_z_unit_checkmap_test.go +++ b/util/gvalid/gvalid_z_unit_feature_checkmap_test.go @@ -159,7 +159,6 @@ func Test_CheckMap2(t *testing.T) { } } -// 如果值为nil,并且不需要require*验证时,其他验证失效 func Test_CheckMapWithNilAndNotRequiredField(t *testing.T) { data := map[string]interface{}{ "id": "1", diff --git a/util/gvalid/gvalid_z_unit_checkstruct_test.go b/util/gvalid/gvalid_z_unit_feature_checkstruct_test.go similarity index 100% rename from util/gvalid/gvalid_z_unit_checkstruct_test.go rename to util/gvalid/gvalid_z_unit_feature_checkstruct_test.go diff --git a/util/gvalid/gvalid_z_unit_customerror_test.go b/util/gvalid/gvalid_z_unit_feature_custom_error_test.go similarity index 100% rename from util/gvalid/gvalid_z_unit_customerror_test.go rename to util/gvalid/gvalid_z_unit_feature_custom_error_test.go diff --git a/util/gvalid/gvalid_z_unit_custom_rule_test.go b/util/gvalid/gvalid_z_unit_feature_custom_rule_test.go similarity index 100% rename from util/gvalid/gvalid_z_unit_custom_rule_test.go rename to util/gvalid/gvalid_z_unit_feature_custom_rule_test.go diff --git a/util/gvalid/gvalid_z_unit_i18n_test.go b/util/gvalid/gvalid_z_unit_feature_i18n_test.go similarity index 100% rename from util/gvalid/gvalid_z_unit_i18n_test.go rename to util/gvalid/gvalid_z_unit_feature_i18n_test.go diff --git a/util/gvalid/gvalid_z_unit_basic_all_test.go b/util/gvalid/gvalid_z_unit_feature_rule_test.go similarity index 99% rename from util/gvalid/gvalid_z_unit_basic_all_test.go rename to util/gvalid/gvalid_z_unit_feature_rule_test.go index d1077000d..af280181f 100755 --- a/util/gvalid/gvalid_z_unit_basic_all_test.go +++ b/util/gvalid/gvalid_z_unit_feature_rule_test.go @@ -361,6 +361,7 @@ func Test_PhoneLoose(t *testing.T) { t.AssertNE(err6, nil) }) } + func Test_Telephone(t *testing.T) { gtest.C(t, func(t *gtest.T) { rule := "telephone"