Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a2f9647

Browse files
committed
config: add failing test for an external modification
We currently use the timestamp in order to decide whether a config file has changed since we last read it. This scheme falls down if the file is written twice within the same second, as we fail to detect the file change after the first read in that second.
1 parent d571a54 commit a2f9647

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

tests/config/stress.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,23 @@ void test_config_stress__complex(void)
107107

108108
git_config_free(config);
109109
}
110+
111+
void test_config_stress__quick_write(void)
112+
{
113+
git_config *config_w, *config_r;
114+
const char *path = "./config-quick-write";
115+
const char *key = "quick.write";
116+
int32_t i;
117+
118+
/* Create an external writer for one instance with the other one */
119+
cl_git_pass(git_config_open_ondisk(&config_w, path));
120+
cl_git_pass(git_config_open_ondisk(&config_r, path));
121+
122+
/* Write and read in the same second (repeat to increase the chance of it happening) */
123+
for (i = 0; i < 10; i++) {
124+
int32_t val;
125+
cl_git_pass(git_config_set_int32(config_w, key, i));
126+
cl_git_pass(git_config_get_int32(&val, config_r, key));
127+
cl_assert_equal_i(i, val);
128+
}
129+
}

0 commit comments

Comments
 (0)